Page 1 of 1

how to execute process if time with seconds

Posted: Sat Jan 24, 2004 7:36 am
by smarty
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!";

Posted: Sat Jan 24, 2004 5:34 pm
by Jade
what the heck?? could you please tell us what this is all about? Do you need help or what?

Jade (or is it just me?)

Posted: Sat Jan 24, 2004 6:54 pm
by ilovetoast
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

Posted: Sun Jan 25, 2004 1:44 am
by smarty
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

...

Posted: Sun Jan 25, 2004 9:19 am
by AVATAr
mmm so? nice, but????

let me concentrate a bit.... mmm i receiving a transmition direct to my neural system... oh oh oh. boing! ???

please illuminate us with some question!

Posted: Sun Jan 25, 2004 9:34 am
by smarty
1. How to make this MySQL query
2. How to make while loop if times more
3. How put seconds automatically in sleep()

Posted: Mon Jan 26, 2004 9:32 am
by Jade

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
}

?>