Posted on Jul 16, 2011

One of the important steps you need to do when setting up a new Drupal site is creating a cronjob that hits up your Drupal install. Or at least it used to be an important step in the past.  Poormanscron is a module that simulates a crontab by keeping track of the time and then running Drupal's cron task whenever a page on your site is loaded around the right time, and it has been added to core in Drupal 7.  Finding this out explained where all these mysterious cron calls in my log were coming from!

Even still, I wanted to go through the crontab setup process anyways, as I was learning the ins and outs of my new hosting company's control panel.  (And as mentioned, Poormanscron will only run when a page is accessed, so if your site doesn't get a lot of hits, your cron won't run as often as you like)

I mucked around with what I thought would be the right command line call, based on Dreamhost's documentation, but that only really worked for scripts that were self-contained, something that Drupal's cron.php file is definitely not doing.  I came across this article on executing Drupal's cronjob in shared environments, which gave me some workable options, and even though cron seemed to be running, I was still getting weird errors in my log. ("Cron could not run because an invalid key was used" and notices of "Undefined index" for REMOTE_ADDR and REQUEST_METHOD and so on)

The "invalid key" error made me curious, so I started Googleing and learned that Drupal 7 now has a cron key, a new security feature that creates a unique key during installation that you use to access cron.php externally.  Once I found that URL and plugged into one of the solutions provided in that previous article, the errors disappeared.  Done!

If by chance you're still running Drupal 6 and you're on Dreamhost, this article over at Drupal.org will probably be helpful.  Or just install Poormanscron.

Categories: 

Tags: 

Comments

Cool

Hey! this is really good post! I really enjoyed reading it. I will bookmark this site to return later. Looking forward to it. Thanks!

Total newb to cron crunks

Hey Stephen, I just got Drupal 7 installed on Dreamhost and am walking through the documentation. I've seen 3 or 4 times now, "It's totally important to set up your cron file after you get the install done", but it's working... I've got the key. Is there any other reason you'd want to modify the cron file right away?

No rush...

No, setting up the cron file is only for getting Drupal's cronjob functions to fire off. If you've got it up and running via Dreamhost's control panel for managing cronjobs, then there's no reason to have to manually edit the cron file. (If I understanding your question correctly)

And with the Poormanscron module now in core, depending on your site usage, you might not even need the cron job at all. (Poormanscron works based on site activity; every time a page is loaded, it checks the last time cron was run, and runs it if it needs to be done; all without modifying a cron file)

If you go to your site and go to the Reports (Reports > Recent Log Entries), filter on "cron", and if you see things happening more or less every few hours, then that's all you really need to worry about.

Hope that helps!