mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
API CHANGE: Added increase_time_limit_to(), which respects safe_mode.
API CHANGE: Added no-arg option to increase_memory_limit_to() git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@80241 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
66b25f1e62
commit
73cfe3ab84
@ -293,11 +293,16 @@ function _t($entity, $string = "", $priority = 40, $context = "") {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Increase the memory limit to the given level if it's currently too low.
|
* Increase the memory limit to the given level if it's currently too low.
|
||||||
* @param A memory limit string, such as "64M"
|
* @param A memory limit string, such as "64M". If omitted, unlimited memory will be set.
|
||||||
*/
|
*/
|
||||||
function increase_memory_limit_to($memoryLimit) {
|
function increase_memory_limit_to($memoryLimit = -1) {
|
||||||
|
$curLimit = ini_get('memory_limit');
|
||||||
|
|
||||||
|
// Can't go higher than infinite
|
||||||
|
if($curLimit == -1) return;
|
||||||
|
|
||||||
// Increase the memory limit if it's too low
|
// Increase the memory limit if it's too low
|
||||||
if(translate_memstring($memoryLimit) > translate_memstring(ini_get('memory_limit'))) {
|
if($memoryLimit == -1 || translate_memstring($memoryLimit) > translate_memstring($curLimit)) {
|
||||||
ini_set('memory_limit', $memoryLimit);
|
ini_set('memory_limit', $memoryLimit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -315,4 +320,22 @@ function translate_memstring($memString) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increase the time limit of this script. By default, the time will be unlimited.
|
||||||
|
* @param $timeLimit The time limit in seconds. If omitted, no time limit will be set.
|
||||||
|
*/
|
||||||
|
function increase_time_limit_to($timeLimit = null) {
|
||||||
|
if(!ini_get('safe_mode')) {
|
||||||
|
if(!$timeLimit) {
|
||||||
|
set_time_limit(0);
|
||||||
|
} else {
|
||||||
|
$currTimeLimit = ini_get('max_execution_time');
|
||||||
|
if($currTimeLimit && $currTimeLimit < $timeLimit) {
|
||||||
|
set_time_limit($timeLimit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -882,7 +882,7 @@ class Requirements_Backend {
|
|||||||
if(stripos($file, '.js') && $this->combine_js_with_jsmin) {
|
if(stripos($file, '.js') && $this->combine_js_with_jsmin) {
|
||||||
require_once('thirdparty/jsmin/JSMin.php');
|
require_once('thirdparty/jsmin/JSMin.php');
|
||||||
|
|
||||||
set_time_limit(0);
|
increase_time_limit_to();
|
||||||
$fileContent = JSMin::minify($fileContent);
|
$fileContent = JSMin::minify($fileContent);
|
||||||
}
|
}
|
||||||
// write a header comment for each file for easier identification and debugging
|
// write a header comment for each file for easier identification and debugging
|
||||||
|
@ -25,7 +25,7 @@ class i18nTextCollectorTask extends BuildTask {
|
|||||||
* @uses DataObject->collectI18nStatics()
|
* @uses DataObject->collectI18nStatics()
|
||||||
*/
|
*/
|
||||||
public function run($request) {
|
public function run($request) {
|
||||||
set_time_limit(0);
|
increase_time_limit_to();
|
||||||
$c = new i18nTextCollector();
|
$c = new i18nTextCollector();
|
||||||
$restrictModules = ($request->getVar('module')) ? explode(',', $request->getVar('module')) : null;
|
$restrictModules = ($request->getVar('module')) ? explode(',', $request->getVar('module')) : null;
|
||||||
return $c->run($restrictModules);
|
return $c->run($restrictModules);
|
||||||
|
@ -83,9 +83,7 @@ class DatabaseAdmin extends Controller {
|
|||||||
*/
|
*/
|
||||||
function build() {
|
function build() {
|
||||||
// The default time limit of 30 seconds is normally not enough
|
// The default time limit of 30 seconds is normally not enough
|
||||||
if(ini_get("safe_mode") != "1") {
|
increase_time_limit_to(600);
|
||||||
set_time_limit(600);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get all our classes
|
// Get all our classes
|
||||||
ManifestBuilder::create_manifest_file();
|
ManifestBuilder::create_manifest_file();
|
||||||
|
@ -7,9 +7,7 @@
|
|||||||
class QueuedEmailDispatchTask extends DailyTask {
|
class QueuedEmailDispatchTask extends DailyTask {
|
||||||
|
|
||||||
public function process() {
|
public function process() {
|
||||||
if(ini_get("safe_mode") != "1") {
|
increase_time_limit_to();
|
||||||
set_time_limit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "SENDING QUEUED EMAILS\n";
|
echo "SENDING QUEUED EMAILS\n";
|
||||||
|
|
||||||
|
@ -12,9 +12,7 @@ class GD extends Object {
|
|||||||
|
|
||||||
function __construct($filename = null) {
|
function __construct($filename = null) {
|
||||||
// If we're working with image resampling, things could take a while. Bump up the time-limit
|
// If we're working with image resampling, things could take a while. Bump up the time-limit
|
||||||
if(ini_get("safe_mode") != "1") {
|
increase_time_limit_to(300);
|
||||||
set_time_limit(300);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($filename) {
|
if($filename) {
|
||||||
// We use getimagesize instead of extension checking, because sometimes extensions are wrong.
|
// We use getimagesize instead of extension checking, because sometimes extensions are wrong.
|
||||||
|
@ -995,14 +995,12 @@ JS
|
|||||||
unset($this->cachedSourceItems);
|
unset($this->cachedSourceItems);
|
||||||
$oldShowPagination = $this->showPagination;
|
$oldShowPagination = $this->showPagination;
|
||||||
$this->showPagination = false;
|
$this->showPagination = false;
|
||||||
$oldLimit = ini_get('max_execution_time');
|
|
||||||
set_time_limit(0);
|
|
||||||
|
|
||||||
|
increase_time_limit_to();
|
||||||
|
|
||||||
$result = $this->renderWith(array($this->template . '_printable', 'TableListField_printable'));
|
$result = $this->renderWith(array($this->template . '_printable', 'TableListField_printable'));
|
||||||
|
|
||||||
$this->showPagination = $oldShowPagination;
|
$this->showPagination = $oldShowPagination;
|
||||||
set_time_limit($oldLimit);
|
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
@ -22,17 +22,44 @@ class MemoryLimitTest extends SapphireTest {
|
|||||||
|
|
||||||
increase_memory_limit_to('1G');
|
increase_memory_limit_to('1G');
|
||||||
$this->assertEquals('1G', ini_get('memory_limit'));
|
$this->assertEquals('1G', ini_get('memory_limit'));
|
||||||
|
|
||||||
|
// No argument means unlimited
|
||||||
|
increase_memory_limit_to();
|
||||||
|
$this->assertEquals(-1, ini_get('memory_limit'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function testIncreaseTimeLimitTo() {
|
||||||
|
set_time_limit(6000);
|
||||||
|
|
||||||
|
// It can go up
|
||||||
|
increase_time_limit_to(7000);
|
||||||
|
$this->assertEquals(7000, ini_get('max_execution_time'));
|
||||||
|
|
||||||
|
// But not down
|
||||||
|
increase_time_limit_to(5000);
|
||||||
|
$this->assertEquals(7000, ini_get('max_execution_time'));
|
||||||
|
|
||||||
|
// 0/nothing means infinity
|
||||||
|
increase_time_limit_to();
|
||||||
|
$this->assertEquals(0, ini_get('max_execution_time'));
|
||||||
|
|
||||||
|
// Can't go down from there
|
||||||
|
increase_time_limit_to(10000);
|
||||||
|
$this->assertEquals(0, ini_get('max_execution_time'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
|
|
||||||
private $origLimit;
|
private $origMemLimit, $origTimeLimit;
|
||||||
|
|
||||||
function setUp() {
|
function setUp() {
|
||||||
$this->origLimit = ini_get('memory_limit');
|
$this->origMemLimit = ini_get('memory_limit');
|
||||||
|
$this->origTimeLimit = ini_get('max_execution_time');
|
||||||
}
|
}
|
||||||
function tearDown() {
|
function tearDown() {
|
||||||
ini_set('memory_limit', $this->origLimit);
|
ini_set('memory_limit', $this->origMemLimit);
|
||||||
|
set_time_limit($this->origTimeLimit);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user