diff --git a/src/img-optm.cls.php b/src/img-optm.cls.php index f1659dc30..28d18ba25 100644 --- a/src/img-optm.cls.php +++ b/src/img-optm.cls.php @@ -937,6 +937,7 @@ public function pull($manual = false) { global $wpdb; $timeoutLimit = ini_get('max_execution_time'); + $endts = time() + $timeoutLimit; self::debug('' . ($manual ? 'Manually' : 'Cron') . ' pull started [timeout: ' . $timeoutLimit . 's]'); @@ -964,7 +965,14 @@ public function pull($manual = false) $server_list = array(); while ($img_rows = $wpdb->get_results($_q)) { - set_time_limit(600); + if (function_exists('set_time_limit')) { + $endts += 600; + set_time_limit(600); + } + if ($endts - time() < 10) { + self::debug("🚨 End loop due to timeout limit reached " . $timeoutLimit . "s"); + break; + } /** * Update cron timestamp to avoid duplicated running