diff --git a/applications/dashboard/controllers/class.dbacontroller.php b/applications/dashboard/controllers/class.dbacontroller.php index 514fdc47860..c6c661cd900 100644 --- a/applications/dashboard/controllers/class.dbacontroller.php +++ b/applications/dashboard/controllers/class.dbacontroller.php @@ -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) { diff --git a/applications/dashboard/models/class.importmodel.php b/applications/dashboard/models/class.importmodel.php index afdcd9e7fd0..82e15d91e7c 100644 --- a/applications/dashboard/models/class.importmodel.php +++ b/applications/dashboard/models/class.importmodel.php @@ -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(); @@ -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'; @@ -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(); diff --git a/library/core/functions.general.php b/library/core/functions.general.php index ebf597745be..fe5400d2042 100644 --- a/library/core/functions.general.php +++ b/library/core/functions.general.php @@ -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; + } +}