1 backup.class.inc | protected Backup::prepareEnvironment() |
Prepare the PHP environment for performing a backup or restore.
File
- core/
includes/ backup/ backup.class.inc, line 362 - Contains the Backup base class.
Class
- Backup
- Base class for creating backups.
Code
protected function prepareEnvironment() {
// If not in 'safe mode', increase the maximum execution time.
$backup_max_time = $this->settings['backup_max_time'];
if (!ini_get('safe_mode') && strpos(ini_get('disable_functions'), 'set_time_limit') === FALSE && ini_get('max_execution_time') < $backup_max_time) {
backdrop_set_time_limit($backup_max_time);
}
// Conditionally increase the memory limit.
// Get the current PHP memory limit.
$php_memory_limit = ini_get('memory_limit');
// If the memory limit is set to -1, there's no need to do anything.
if ($php_memory_limit != '-1') {
// Convert the PHP memory limit to bytes.
$php_memory_limit_bytes = parse_size($php_memory_limit);
// Convert the instance settings memory limit to bytes.
$backup_memory_limit_bytes = parse_size($this->settings['memory_limit']);
// Increase the memory limit.
if ($php_memory_limit_bytes < $backup_memory_limit_bytes) {
// Ensure ini_set() is not disabled.
if (!strpos(ini_get('disable_functions'), 'ini_set')) {
// Convert bytes to megabytes, add the 'M' unit.
$backup_memory_limit = round($backup_memory_limit_bytes / 1024 / 1024) . 'M';
// Update the PHP memory limit.
ini_set('memory_limit', $backup_memory_limit);
}
}
}
if ($this->settings['verbose']) {
$this->log('Memory limit: %limit', array('%limit' => ini_get('memory_limit')), self::LOG_SUCCESS);
}
}