[prev in list] [next in list] [prev in thread] [next in thread]
List: php-windows
Subject: [PHP-WIN] Re: [PHP-GTK] Time
From: "Steph" <Steph.Fox () btinternet ! com>
Date: 2001-03-31 13:28:25
[Download RAW message or body]
Yes Chris. It's Saturday.
> )
----- Original Message -----
From: "Chris Chabot" <chabotc@reviewboard.com>
To: "Steph" <steph.fox@btinternet.com>; "Josh Seward" <js389599@ohiou.edu>; \
<php-windows@lists.php.net>; "php-gtk" <php-gtk@lists.php.net>
Sent: Saturday, March 31, 2001 12:38 PM
Subject: Re: [PHP-GTK] Time
Oh about the time being of in the folowing loop due to exec
while (1)
sleep (60*60)
exec('program')
end
that is indeed true ... however, dudes, am i the only programmer on this list ?? the \
solution is so simple i didnt thought i'd have to mention it, imagine the folowing
$seconds_in_hour = 60 * 60; // 60 minutes * 60 seconds
$run_time = 0;
while (1) {
sleep ($seconds_in_hour - $run_time);
$run_time = time();
exec('application');
$run_time = time() - $run_time;
}
In other words, the first time the loop triggers, run_time is 0, and in an hour the \
program runs. when it runs the program, it takes the current time in seconds (seconds \
since epoch, 1970) after run is completed, it takes run_time = (time - run_time), in \
other words, how many seconds did execution take. Then the next time the while loops \
it sleeps (seconds_in_hour - the time it took to run the application), so it should \
trigger in an hour
This will still cause a 'drift', since a fraction of a second is gained/lost every \
time, since the measurement used is seconds.. If this is a problem (in most cases it \
wont be, drifting a max of 23 seconds a day?), then you should recode the run_time \
calculation to use usleep and microtime, which would result in the folowing
// microtime returns a string like "32423423 233", the first part is seconds
// second is microseconds, function returns time as float (ie 1213324.333)
function get_ms_time()
{
list($usec,$sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
$micro_seconds_in_hour = 60 * 60 * 1000; // 60 minutes * 60 seconds * 1000 Ms
$run_time = 0;
while (1) {
usleep ($micro_seconds_in_hour - $micro_run_time);
$run_time = (float)get_ms_time();
exec('application');
$run_time = (float)get_ms_time() - (float)$run_time;
$run_time = ceil($run_time * 1000);
}
this loop does the same, but uses a float (integer with decimals) to calculate the \
run time, with a Mili Second accuracy. Then it converts the float (wich is something \
like '12.345') to Ms (12345) and does a usleep on that amount of Ms.
Hope this puts an end to this thread, this should give u plenty of tools to solve the \
problem Thus endeth the lesson for today
-- Chris
Chris Chabot wrote:
> No both time and sleep use seconds.
> see http://www.php.net/manual/en/function.sleep.php and \
> http://www.php.net/manual/en/function.time.php respectivly.
> if you want to use milliseconds, you need to use usleep
> see http://www.php.net/manual/en/function.usleep.php
>
> just nitpicking my last few awake moments of the day :)
>
> -- Chris
>
> Steph wrote:
>
> > Seconds? I thought milliseconds?
> >
> > Oh well, suck it and see, Josh!
> > ;)
> >
> > ----- Original Message -----
> > From: "Chris Chabot" <chabotc@reviewboard.com>
> > To: "Josh Seward" <js389599@ohiou.edu>
> > Cc: <php-windows@lists.php.net>; "php-gtk" <php-gtk@lists.php.net>
> > Sent: Saturday, March 31, 2001 4:31 AM
> > Subject: Re: [PHP-GTK] Time
> >
> > Umm the obvious reply would be to go to download.com and browse to see if they \
> > have a shareware version of a cron like application, i am sure they do... i \
> > remember seeing some of those.
> > Otherwise, code a simple php or c or delphi or visual basic app that only does
> >
> > while (1)
> > sleep(60*60);
> > exec('application')
> > end
> >
> > Can't be that hard to write right? :)
> > or even if you wanted it -on- every hour and not every hour, just do a
> > if ( frac (time() / (60*60) ) == 0) {
> > exec('application')
> > }
> > (ie if the dividable time / 'seconds in hour' has no fraction (behind the . or , \
> > depending on locality, its on the hour)
> > I realy hope this wont become a windows support mailing list though, thats kinda \
> > outside of the scope of php-gtk? :)
> > -- Chris
> >
> > Josh Seward wrote:
> >
> > > Hello,
> > >
> > > Is there a way to have php run a script at a certain time? What I really need \
> > > is something like cron on unix systems. I would use windows scheduler but it \
> > > only goes by days. I ned to run this once every hour.
> > > P.S. To let everyone how helped me before. I can now send commands to an \
> > > outside program I am running w/ the fsockopen command. This is after I open the \
> > > prog. with popen. Thank you all for your help., especially Steph and Micheal. \
> > > Your efffort and advice is much appriciated. If your ever in Athens Ohio the \
> > > first round is on me :-)
> >
> > --
> > PHP GTK Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: php-gtk-unsubscribe@lists.php.net
> > For additional commands, e-mail: php-gtk-help@lists.php.net
> > To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
> --
> PHP GTK Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-gtk-unsubscribe@lists.php.net
> For additional commands, e-mail: php-gtk-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net
For additional commands, e-mail: php-windows-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic