diff --git a/app/main/cron/abstractcron.php b/app/main/cron/abstractcron.php new file mode 100644 index 000000000..04b4076da --- /dev/null +++ b/app/main/cron/abstractcron.php @@ -0,0 +1,27 @@ + should be less then execution period + const DEFAULT_MAX_EXECUTION_TIME = 50; + + /** + * set max execution time for cronjobs + * -> Default CLI execution time is "0" -> infinite! + * php.ini settings are ignored! http://php.net/manual/en/info.configuration.php#ini.max-execution-time + * @param int $time + */ + protected function setMaxExecutionTime(int $time = self::DEFAULT_MAX_EXECUTION_TIME){ + ini_set('max_execution_time', $time); + } + +} \ No newline at end of file diff --git a/app/main/cron/cache.php b/app/main/cron/cache.php index 63832068a..2afbe1f8a 100644 --- a/app/main/cron/cache.php +++ b/app/main/cron/cache.php @@ -10,7 +10,7 @@ use data\filesystem\Search; -class Cache { +class Cache extends AbstractCron { const LOG_TEXT = '%s [%\'_10s] files, size [%\'_10s] byte, not writable [%\'_10s] files, errors [%\'_10s], exec (%.3Fs)'; @@ -34,6 +34,7 @@ protected function getExpireMaxTime(\Base $f3): int { * @param \Base $f3 */ function deleteExpiredData(\Base $f3){ + $this->setMaxExecutionTime(); $time_start = microtime(true); // cache dir (dir is recursively searched...) diff --git a/app/main/cron/ccpsystemsupdate.php b/app/main/cron/ccpsystemsupdate.php index 28a6c692f..51e3c1027 100644 --- a/app/main/cron/ccpsystemsupdate.php +++ b/app/main/cron/ccpsystemsupdate.php @@ -10,7 +10,7 @@ use Controller; use DB; -class CcpSystemsUpdate { +class CcpSystemsUpdate extends AbstractCron { const LOG_TEXT = '%s prepare table (%.3F s), jump (%.3F s), kill (%.3F s), update all (%.3F s)'; @@ -35,7 +35,6 @@ class CcpSystemsUpdate { * @return array */ private function prepareSystemLogTables(){ - // get information for all systems from CCP DB $systemController = new Controller\Api\System(); $systemsData = $systemController->getSystems(); @@ -72,6 +71,7 @@ private function prepareSystemLogTables(){ * @param \Base $f3 */ function importSystemData($f3){ + $this->setMaxExecutionTime(); // prepare system jump log table ------------------------------------------------------------------------------ $time_start = microtime(true); diff --git a/app/main/cron/characterupdate.php b/app/main/cron/characterupdate.php index eb795ddb4..fc6b81b4f 100644 --- a/app/main/cron/characterupdate.php +++ b/app/main/cron/characterupdate.php @@ -11,7 +11,7 @@ use Model; -class CharacterUpdate { +class CharacterUpdate extends AbstractCron { /** * default character_log time until a log entry get re-checked by cronjob @@ -41,6 +41,7 @@ protected function getCharacterLogInactiveTime(\Base $f3){ * @throws \Exception */ function deleteLogData(\Base $f3){ + $this->setMaxExecutionTime(); DB\Database::instance()->getDB('PF'); $logInactiveTime = $this->getCharacterLogInactiveTime($f3); @@ -84,6 +85,7 @@ function deleteLogData(\Base $f3){ * @throws \Exception */ function cleanUpCharacterData(\Base $f3){ + $this->setMaxExecutionTime(); DB\Database::instance()->getDB('PF'); /** @@ -96,7 +98,6 @@ function cleanUpCharacterData(\Base $f3){ ':active' => 1 ]); - if(is_object($characters)){ foreach($characters as $character){ /** @@ -115,7 +116,8 @@ function cleanUpCharacterData(\Base $f3){ * @param \Base $f3 * @throws \Exception */ - function deleteAuthenticationData($f3){ + function deleteAuthenticationData(\Base $f3){ + $this->setMaxExecutionTime(); DB\Database::instance()->getDB('PF'); /** diff --git a/app/main/cron/mapupdate.php b/app/main/cron/mapupdate.php index 99a61314d..313816f83 100644 --- a/app/main/cron/mapupdate.php +++ b/app/main/cron/mapupdate.php @@ -11,7 +11,7 @@ use lib\Config; use Model; -class MapUpdate { +class MapUpdate extends AbstractCron { const LOG_TEXT_MAPS = '%s (%d maps)'; @@ -25,6 +25,7 @@ class MapUpdate { * @throws \Exception\PathfinderException */ function deactivateMapData(\Base $f3){ + $this->setMaxExecutionTime(); $privateMapLifetime = (int)Config::getMapsDefaultConfig('private.lifetime'); if($privateMapLifetime > 0){ @@ -49,6 +50,7 @@ function deactivateMapData(\Base $f3){ * @throws \Exception */ function deleteMapData(\Base $f3){ + $this->setMaxExecutionTime(); $pfDB = DB\Database::instance()->getDB('PF'); $deletedMapsCount = 0; @@ -87,6 +89,7 @@ function deleteMapData(\Base $f3){ * @throws \Exception */ function deleteEolConnections(\Base $f3){ + $this->setMaxExecutionTime(); $eolExpire = (int)$f3->get('PATHFINDER.CACHE.EXPIRE_CONNECTIONS_EOL'); if($eolExpire > 0){ @@ -131,6 +134,7 @@ function deleteEolConnections(\Base $f3){ * @throws \Exception */ function deleteExpiredConnections(\Base $f3){ + $this->setMaxExecutionTime(); $whExpire = (int)$f3->get('PATHFINDER.CACHE.EXPIRE_CONNECTIONS_WH'); if($whExpire > 0){ @@ -176,6 +180,7 @@ function deleteExpiredConnections(\Base $f3){ * @param \Base $f3 */ function deleteSignatures(\Base $f3){ + $this->setMaxExecutionTime(); $signatureExpire = (int)$f3->get('PATHFINDER.CACHE.EXPIRE_SIGNATURES'); if($signatureExpire > 0){ diff --git a/app/main/cron/statisticsupdate.php b/app/main/cron/statisticsupdate.php index 266367090..ac9f78ca7 100644 --- a/app/main/cron/statisticsupdate.php +++ b/app/main/cron/statisticsupdate.php @@ -9,7 +9,7 @@ namespace cron; use DB; -class StatisticsUpdate { +class StatisticsUpdate extends AbstractCron { const LOG_TEXT_STATISTICS = '%s (%d rows)'; @@ -20,6 +20,8 @@ class StatisticsUpdate { * @param \Base $f3 */ function deleteStatisticsData(\Base $f3){ + $this->setMaxExecutionTime(); + $currentYear = (int)date('o'); $currentWeek = (int)date('W'); $expiredYear = $currentYear - 1;