Drupal - How do you disable Cron on a staging / dev server?
Yes, you can do this in your settings.php file (as you have mentioned that is the only difference between versions).
You would do it like this (in your settings.php file):
// Disable drupal's built in cron trigger.
$conf['cron_safe_threshold'] = 0;
For more information see Defining variables in a site's settings.php $conf array.
Edit How this works is:
- Variables are loaded from the database (or the cache if they have already been cached).
- If those variables were not already in the cache they are saved to the cache.
- The $conf variables from the settings file are added to the variables and take precedence over variables from the database.
So variables from the database are cached, but variables from settings.php are not.
As others have said there are modules out there to switch environments between different servers. For example a development server vs testing server vs production server.
A few are: Environment and Drush Environment.
Environment for example lets you write your own hook to easily manage what happens when you switch to a new environment. From the module page:
/**
* Implementation of hook_environment_switch().
*/
function YOUR_MODULE_environment_switch($target_env, $current_env) {
// Declare each optional development-related module
$devel_modules = array(
'bulk_export',
'context_ui',
'devel',
'devel_generate',
'devel_node_access',
'imagecache_ui',
'update',
'spaces_ui',
'views_ui',
);
switch ($target_env) {
case 'production':
module_disable($devel_modules);
drupal_set_message('Disabled development modules');
return;
case 'development':
module_enable($devel_modules);
drupal_set_message('Enabled development modules');
return;
}
}
?>
You could with little trouble write a line of PHP that turns off Cron if your in the Testing
environment server. I'm using Environment's hook on 1 project to perform the following tasks on a non-production server:
module_enable($devel_modules); // A list of modules to enable.
drupal_flush_all_caches();
drupal_set_message('Enabled development/staging modules');
// Configure Enviroment Indicator Module
variable_set('environment_indicator_color',"#d00c0c");
variable_seT('environment_indicator_margin', 1);
variable_set('environment_indicator_position', "right");
variable_set('environment_indicator_text',"MY STAGING SERVER");
variable_set('environment_indicator_enabled','1');
drupal_set_message(t('Configured environment indicator.'));
Go to /admin/config/system/cron and set it to 'Never'. If you have an external crontab task, disable it.