Dear drupal webmaster newbies, this is for you!

Now it's possible to run cron.php regularily, without any access to the server or without any knowledge about servers and crontab!

Just put these simple PHP lines in a block of your Drupal site, better if mostly present, or create a new block with them:

<?php
$tmstmp=mktime();
$last=file_get_contents("lastcron.txt");
if(($tmstmp-$last)>(60*60*6))
{
 $pntr=fopen('lastcron.txt', 'w');
 if(fwrite($pntr, $tmstmp))
 { 
   mail ("dest","cron OK","OK");
   include ("cron.php"); 
 }
 else
 { 
   mail ("dest","cron FAIL","FAIL"); 
 }
 fclose($point);
}
?>

Of curse replace the lines containing mail ("dest", with your own email address instead of dest.

Then you have to create a text file (lascron.txt) filled with whatever you want (eg: 123456 is ok!) and upload it on the server in the same folder of cron.php (usually the root of your FTP access). Then set file permission to 666 (rw,rw,rw): I've done it with FileZilla, right click on the uploaded file, file attributes, put the flag on write permission for everyone... anyway ... do it, no matter how ;)

Done!

Now 'cron.php' will run more or less regularly, depending on how frequently your site is visited and you'll receive also an email notification.
In the sample I'm tryng to run it every 6 hours and not more frequently: the corresponding code for that is (60*60*6), that calculate the number of seconds in 6 hours.

If you like (or even not!) this script, please leave me a comment on my web site: http://www.diegobelotti.com/?q=cron_script_eng

Comments

pwolanin’s picture

There's also a module that does this: http://drupal.org/project/poormanscron

---
Work: BioRAFT

diego belotti’s picture

I don't know if the poormanscron module sends email, anyway my script is for "very very poor mans" :))) that can't even install a new module!

I haven't tried this module yet, probabily is much better than my script. For sure, the "some lines" script is easier to modify and personalize... I hope this can help someone anyway! ;)

Diego
http://www.diegobelotti.com/