How to simulate a cron in php
By liviu - Posted on December 8th, 2008
Tagged:
How to simulate a cron in php?
There are two nice functions in php called ignore_user_abort and set_time_limit. With them you can create a cron in php like this:
<?php
ignore_user_abort(TRUE); // run script in background
set_time_limit(0); // run script forever
$interval=60*15; // do every 15 minutes...
do{
// add the script that has to be ran every 15 minutes here
// ...
sleep($interval); // wait 15 minutes
}while(true);
?>
The cron is ran every 60*15 seconds.
The bad part about this is that if the server restarts the cron stops (it's bye, bye cron) until this script is ran again.
Thx spiritual-coder at spiritual-coder dot com for this.
Bookmark/Search this post with:
- liviu's blog
- Login or register to post comments
Delicious
Digg
StumbleUpon
Propeller
Reddit
Magnoliacom
Newsvine
Furl
Facebook
Google
Yahoo
Technorati
Icerocket