|PHP scripts archive|
|PHP vCard class|
Usually regular tasks like backup up the site's database are run using cron jobs. With cron jobs, you can exactly plan when a certain command is to be executed. But most homepage owners can't create cron jobs on their web server – providers demand some extra money for that.
The only thing that's certain to happen quite regularly on a web page are page requests. This is where pseudo-cron comes into play: With every page request it checks if any cron jobs should have been run since the previous request. If there are, they are run and logged.
Pseudo-cron uses a syntax very much like the Unix cron's one. For an overview of the syntax used, see a page of the UNIXGEEKS. The syntax pseudo-cron uses is different from the one described on that page in the following points:
- there is no user column
- the executed command has to be an include()able file (which may contain further PHP code)
#comments start with '#'
#mi h d m dow job comment
0 5 * * Sun cronjobs/dump.inc.php # make db dump every sunday at 5 am
40 5 2 * * cronjobs/sendlog.inc.php # send last month's web server logs
*/15 8-19 * * Mon-Fri cronjobs/refr_ext.inc.php # refresh external news sources
- runs any PHP script
- periodical or time-controlled script execution
- logs all executed jobs
- can be run from an IMG tag in an HTML page
- follows Unix cron syntax for crontabs
- sends an email with the results
- Modify the variables in the config section below to match your server.
- Write a PHP script that does the job you want to be run regularly. Be sure that any paths in it are relative to the script that include()s pseudo-cron.
- Set up your crontab file with your script.
- Include pseudo-cron.inc.php in a high traffic page.
- Wait for the next scheduled run :)
logMessage("log a message").