In certain situations you need more control of your cron tasks, execution times, and methods. Check out the SuperCron and Elysia Cron modules as alternative solutions. Both give you the ability to order, manage, disable, and execute your cron tasks, among a slew of other functionality. If you are familiar with Linux crontabs and need that level of scheduling and control, see Elysia Cron.
On a recent project, I struggled to get a massive cron hook to complete, and at one point, some of the tasks required a Batch API implementation to manage system resources. I eventually decided to pull the cron task out of the Drupal/Apache/web environment to execute it on the shell in a separate crontab. Here's the gist of the PHP script I put in my Drupal docroot.
<?php
// check if this is web traffic, versus CLI
if (isset($_SERVER['HTTP_USER_AGENT'])) {
header('HTTP/1.1 403 Forbidden');
die('You are not authorized to access this page.');
}
// set environment variables:
// remove time limit of script
set_time_limit(0);
// increase memory usage
ini_set('memory_limit', '256M');
// ensure script is being executed from Drupal docroot
$docroot_path = dirname($_SERVER['SCRIPT_NAME']);
if (getcwd() != $docroot_path) {
chdir($docroot_path);
}
// set bootstrap variables:
// these lines ensure multi-site environments will work with a bootstrap
$_SERVER['HTTP_HOST'] = 'www.myhostname.com';
$_SERVER['SCRIPT_NAME'] = '/' . basename(__file__);
// include Drupal bootstrap
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// check for custom module and cron hook
if (!module_exists(array('MYMODULE')) || !function_exists('MYMODULE_cron')) {
die('Module is not enabled.');
}
// execute custom cron hook
MYMODULE_cron();
?>I then added a line in my crontab on the shell
$ crontab -e
# file contents:
#min hour dayMonth month dayWeek command
0 0 * * * /usr/bin/php /path/to/drupal/docroot/cron.custom.phpThe above crontab executes my custom cron hook once a day.









