how to execute process if time with seconds

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
smarty
Forum Newbie
Posts: 4
Joined: Mon Dec 29, 2003 10:47 am
Location: Tallinn

how to execute process if time with seconds

Post 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!";
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Post 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?)
ilovetoast
Forum Contributor
Posts: 142
Joined: Thu Jan 15, 2004 7:34 pm

Post 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
smarty
Forum Newbie
Posts: 4
Joined: Mon Dec 29, 2003 10:47 am
Location: Tallinn

Post 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

...
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post 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!
smarty
Forum Newbie
Posts: 4
Joined: Mon Dec 29, 2003 10:47 am
Location: Tallinn

Post 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()
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Post 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
}

?>
Post Reply