Let your visitors run Drupal cron for you

Sometimes (or mostly on shared hosts) wo dont have ssh/shell acces to server to configure crontab. In this case we need to run crons manually or register for a paid cron-service or find an other solution. For my solution I need just one visitor a day to request a hidden img-tag. And its working; at least once a day Drupal runs cron.php.

  • Create a block called something like "run cron manually"
  • Activate your block; move to footer region etc
  • Put following code and save as PHP-Filter (input format)

Code for "run cron manually with a footer block"

<?php
$now = time();
$last_run = variable_get("cron_last_run", 0);

if( $now-$last_run > 86400 ){
variable_set("cron_last_run", $now);
return "<img src=\"/cron.php\" width=1 height=1 border=0>";
}

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Use <pre> all your html php come here </pre> for your code
  • Allowed HTML tags: <a> <b> <pre> <h1> <h2> <h3> <h4> <h5> <h6> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <div> <style><img> <br> <blockquote>
  • Lines and paragraphs break automatically.
  • You may insert videos with [video:URL]

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.

CafeWebmaster.com(CW) is a free online community for webdevelopers and beginners. Anybody can share their code, articles, tips, tutorials, code-examples or other webdesign related material on the site. Newbies can submit their questions and reply to existing questions. CW does not guarantee or warrant reliability of code, data and information published on the site. Use the site on your own risk. The site takes no responsibility of direct or indirect loss or any kind of harm to its users. The site also doesn't take responsibility of infected files or source code with any kind of infection or viruses, worms, spywares, malwares, trojan horses. CW reserves the right to edit, move, or delete any of content for any reason.