cron

Workaround warnings like "It is not safe to rely on the system's timezone settings..." using strtotime() and date()

When running cron.php from CLI you might get a warning like "It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead ..."

Best solution is to set the time zone in the CLI version of php.ini, suggested in http://drupal.org/node/615438#comment-2195208

Cron semaphore

Sometimes you want to avoid running massive operations during cron run, then you might want to at least first check if it is running. When cron runs it sets a variable called cron_semaphore in the variable table.

How to handle heavy calculations in the background in Drupal

Say you have a data warehouse or data mart in your Drupal installation and you have to make a quite heavy calculation on a node save, but you don't want the users to wait for too long. Then you have to add the process to the background.

One way of doing it is to set a flag and have a function called by hook_cron doing the job. But you might not want to wait for cron to run and you don't want to hammer the site with cron.

Running cron as administrator or another user in Drupal

Here are some links and notes about cron on Drupal 6. When you let the server run cron on your Drupal installation it runs as Anonymous user (uid=0) and if you have some tasks that requires admin access it will leave those. One workaround is to temporary fake another user, like it was admin (uid=1) who run the cronjob.

This is a safer way to temporary change the user because if the function crashes it has not saved the temporary user. If the function succeed it returns to Anonymous user when finished.