Skip to content

Commit

Permalink
Merge pull request #3494 from vanilla/fix/max-execution-time
Browse files Browse the repository at this point in the history
Fix that only allows increase of max_execution_time.
  • Loading branch information
linc committed Jan 26, 2016
2 parents 62c42e7 + c3c3eec commit 1b2013f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion applications/dashboard/controllers/class.dbacontroller.php
Expand Up @@ -43,7 +43,7 @@ public function initialize() {
* @throws Gdn_UserException
*/
public function counts($Table = false, $Column = false, $From = false, $To = false, $Max = false) {
set_time_limit(300);
increaseMaxExecutionTime(300);
$this->permission('Garden.Settings.Manage');

if ($Table && $Column && strcasecmp($this->Request->requestMethod(), Gdn_Request::INPUT_POST) == 0) {
Expand Down
6 changes: 3 additions & 3 deletions applications/dashboard/models/class.importmodel.php
Expand Up @@ -1302,7 +1302,7 @@ protected function _LoadTableLocalInfile($Tablename, $Path) {
*/
protected function _LoadTableWithInsert($Tablename, $Path) {
// This option could take a while so set the timeout.
set_time_limit(60 * 10);
increaseMaxExecutionTime(60 * 10);

// Get the column count of the table.
$St = Gdn::structure();
Expand Down Expand Up @@ -1548,7 +1548,7 @@ public function processImportDb() {
*/
public function processImportFile() {
// This one step can take a while so give it more time.
set_time_limit(60 * 10);
increaseMaxExecutionTime(60 * 10);

$Path = $this->ImportPath;
$BasePath = dirname($Path).DS.'import';
Expand Down Expand Up @@ -1934,7 +1934,7 @@ public function &tables($TableName = '') {
*/
public function updateCounts() {
// This option could take a while so set the timeout.
set_time_limit(60 * 10);
increaseMaxExecutionTime(60 * 10);

// Define the necessary SQL.
$Sqls = array();
Expand Down
28 changes: 28 additions & 0 deletions library/core/functions.general.php
Expand Up @@ -4433,3 +4433,31 @@ function userAgentType($value = null) {
return $type = 'desktop';
}
}

if (!function_exists('increaseMaxExecutionTime')) {
/**
* Used to increase php max_execution_time value.
*
* @param int $maxExecutionTime PHP max execution time in seconds.
* @return bool Returns true if max_execution_time was increased (or stayed the same) or false otherwise.
*/
function increaseMaxExecutionTime($maxExecutionTime) {

$iniMaxExecutionTime = ini_get('max_execution_time');

// max_execution_time == 0 means no limit.
if ($iniMaxExecutionTime === '0') {
return true;
}

if (((string)$maxExecutionTime) === '0') {
return set_time_limit(0);
}

if (!ctype_digit($iniMaxExecutionTime) || $iniMaxExecutionTime < $maxExecutionTime) {
return set_time_limit($maxExecutionTime);
}

return true;
}
}

0 comments on commit 1b2013f

Please sign in to comment.