In: , , , , ,
On: 2004 / 10 / 12
Shorter URL for this post: http://ozh.in/30

I've been asked a few hints on what to do when you don't have access to crontab on your server (in regards to my del.icio.us hack taga.licio.us)

Basically, you have two choices : a script to do stuff every time someone loads your blog page (such a script firsts get the current time to determine if there is actually something to do) or an external agent like a website monitoring service.

Scripts to emulate crontab

There are various scripts around, I'll recommend two I have tried and found efficient :

  • Pseudocron, a simple PHP script
  • Fake Cron, the first one I've used even before knowing about crontab (Perl script)

The scripts itselves are easy to configure, just edit them where commented. Include the script file in your main page footer for example. Every time your page is loaded, the script runs : it checks current time, and according to your crontab job list, does nothing or starts action. The more your page is loaded, the more efficient the script will be. This is a near perfect solution if your blog gets around at least one or two hits an hour.

Using a website monitoring service

This is an even easier solution to implement, since there can be no coding involved. There are dozens of free monitoring services around the net, the idea is to sign up with a free service that regularly checks a given URL (usually every one or two hours). Don't try something with services that ping or get HTTP headers to check if a host is online, you want something that actually fetches a page.

A good start to list those services could be Google. My choice goes to Alal's Uptime, which checks every 2 hours a page and sends you an email if it cannot read the word "Success" in it.

So, to use Uptime to regularly load a page, you just need to modify the script so that it echoes "Success" once its job is done.

Shorter URL

Want to share or tweet this post? Please use this short URL: http://ozh.in/30

Metastuff

This entry "PHP Crontab replacements" was posted on 12/10/2004 at 11:29 pm and is tagged with , , , , ,
Watch this discussion : Comments RSS 2.0.

3 Blablas

  1. Oscar M. says:

    You can also emulate cron pretty simply using caching (such as PEAR Cache) and the date() function. I wrote about that here:

    http://www.oscarm.org/news/phpdevel/502.php

  2. Another option is to schedule PHP scripts to run specifically when a web page is accessed; Jerrata Backbone does this, and supports invoking multiple scripts when a page is visited.

  3. scott says:

    i had a little "tip of the day" script drawing tis from a mysql table. simply had a table with a value called last_updated; when a user accessed the page it checked if the current date matched the last_updated date. if not, it ran the script for a new tip and changed the date in the table to the current date.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Gravatars: Curious about the little images next to each commenter's name ? Go to Gravatar and sign for a free account
Spam: Various spam plugins may be activated. I'll put pins in a Voodoo doll if you spam me.

Read more ?