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:
you may not use abbreviations (Mon, Tue, ...) for day of weeknew in v1.1!
there is no user column
the executed command has to be an include()able file (which may contain further PHP code)
All job definitions are made in a text file on the server with a user-definable name (usually crontab.txt).
Here is an example of a valid crontab file:
#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
The last line will call cronjobs/refr_ext.inc.php every 15 minutes between 8am and 7pm on Monday to Friday.
Features:
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
Usage:
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 :)
Note:
You can log messages from your job script to pseudo-cron's log file by calling
logMessage("log a message")
Version history:
v1.3
15.06.04
added: the number of jobs run during one call of pseudocron can now be limited.
added: additional script to call pseudocron from an HTML img tag
improved storage of job run times
fixed a bug with jobs marked as run although they did not complete
v1.2.2
17.01.04
added: send an email for each completed job
improved: easier cron job configuration (relative to pseudo-cron, not to calling script. Please read the release notes in the source.
v1.2.1
03.02.03
fixed: jobs may be run too often under certain conditions
added: global debug switch
v1.2
31.01.03
added: more documentation
changed: log file should now be easier to use
changed: log file name
v1.1
29.01.03
changed: renamed pseudo-cron.php to pseudo-cron.inc.php
fixed: comments at the end of a line don't work
fixed: empty lines in crontab file create nonsense jobs
changed: log file grows big very quickly
changed: included config file in main file to avoid directory confusion
added: day of week abbreviations may now be used (three letters, english)
v1.0
initial release
last changed on 06-18-04
Quick feedback
Feedback heard: New support board! by Kai Blankenhorn (11-17-04) Some of you seem to like the idea to have a forum here, so there it is! It is still quite empty, but I've just put links to it all over my site so everybody at leasts notices. Now all you have to do is post :-)
Feedback requested: Support board? by Kai Blankenhorn (10-11-04) Thinking of how to give better support for my scripts: Do you think a support board would be useful? I don't know if I can reach the critical mass of users - right now I have around 100 visits per day for the scripts. Tell me if you would use it!
Processed some email by Kai Blankenhorn (10-11-04) I've finally got the time to process some of the email I've got in the last few weeks. Sorry to anybody whom I couldn't answer! It's pretty hard for me to answer support requests in the little time I can spare.
Anyway, I've found some treasures among the emails :-) FeedCreator is used in the Mambo CMS, and will probably soon be used in TWiki. Snif has two new translations, and pseudocron will have a bugfix in a few days.
finally new releases by Kai Blankenhorn (10-11-04) At last I've managed to put up two new releases of my scripts, snif and FeedCreator. Especially FeedCreator has had much user input and definitely needed a freshup. New feed types are HTML and JavaScript feeds, which can be included in any web page right away. Snif has become more configurable with the new version. You may now create central configuration files to use the same settings for multiple installations of snif within one webspace. Colors can now be configured using external stylesheets. If you have made a new color set for snif, send it to me and I'll put it on my site!
disadvantages of having a job by Kai Blankenhorn (07-07-04) I've started working in a full-time job last week (at sd&m, to be exact, which appears to be a great company so far). Unfortunately this means that I'll have less time for improving my scripts. But I definitely will! Pending are Brazilian Portuguese, Spanish and Greek translations for snif, and some fixes for FeedCreator. I'll see what I can do to create the new releases ASAP.
I'm alway happy to receive your code changes, so if you've made some improvements to one of my scripts, send them to me so other users can profit from them as well!