cron check every minute but if time is with seconds then ....
id | time | msg | status
---------------------------------
3 | 12:35:15 | Hello 3! | idle
2 | 12:35:55 | Hello 2! | idle
1 | 12:34:45 | Hello 1! | idle
cron check and time now 12:34:00
if seconds is 00 and status idle
echo "$msg";
else if seconds 01 – 59 and status idle
count seconds 01-59 // how to make the loop
sleep(45)
echo "Hello 1!";
sleep(10)
echo "Hello 2!";
how to execute process if time with seconds
Moderator: General Moderators
-
ilovetoast
- Forum Contributor
- Posts: 142
- Joined: Thu Jan 15, 2004 7:34 pm
Output buffering using sleep is touch and go at best.
It requires that you flush the output buffer of PHP (and the backend its using). The php manual also decribes a few of the problems you will run into with different web servers, different browsers, etc.
If you want to set up a down to the second time-coordinated client-server app (I'm not quite sure what you're problem is/what you're after) consider Java or at least something besides PHP.
peace
It requires that you flush the output buffer of PHP (and the backend its using). The php manual also decribes a few of the problems you will run into with different web servers, different browsers, etc.
If you want to set up a down to the second time-coordinated client-server app (I'm not quite sure what you're problem is/what you're after) consider Java or at least something besides PHP.
peace
ok my example was wrong
this script work stand-alone in server and don't need any browser.
id | time | command | status
---------------------------------
3 | 12:35:15 | com.php | idle
2 | 12:34:55 | com.php | idle
1 | 12:34:45 | com.php | idle
cron check and time now 12:34:00
if seconds is 00 and status idle
run exec command
else if seconds 01 – 59 and status idle
count how many times 01-59 // how to make the loop
if 2 times (12:34:45 and 12:34:55)
sleep(45)
run command
sleep(10)
run command
next cron check 12:35:00
...
this script work stand-alone in server and don't need any browser.
id | time | command | status
---------------------------------
3 | 12:35:15 | com.php | idle
2 | 12:34:55 | com.php | idle
1 | 12:34:45 | com.php | idle
cron check and time now 12:34:00
if seconds is 00 and status idle
run exec command
else if seconds 01 – 59 and status idle
count how many times 01-59 // how to make the loop
if 2 times (12:34:45 and 12:34:55)
sleep(45)
run command
sleep(10)
run command
next cron check 12:35:00
...
Code: Select all
<?php
//connect to your database up here...
//this will be your CRON file, you should set it to run whenever to check when your seconds is 00
//first of start off with the query
$result = mysql_query("SELECT id, time, command, status FROM tablename") or die ('cannot select initial values');
$row = mysql_fetch_array($result);
$id = $row['id'];
$time = $row['time'];
$command = $row['command'];
$status = $row['status'];
//you'll have to break time apart to get seconds
if ($seconds == 00 && $status == "idle")
{
//run exec command
}
else if ($seconds >= 01 && $status == "idle")
{
//count how many times 01-59 (i have no clue what you mean here)
//i'm guessing you want something like this... I'm basing this query as if
//you had a seconds field in your table. Otherwise you'd have to select by
//time
$result = mysql_query("SELECT id FROM tablename WHERE seconds >= 01") or die ('cannot select seconds 01-59');
$totalrow = mysql_num_rows($result); \\will return the number of rows with seconds greater then 00
//then i have no clue what you're trying to do with your sleep thing. Good luck with that.
//sleep stuff would go down here
}
?>