From e87af71bda73e77fe5ffe2f4ed95470b6bc403e7 Mon Sep 17 00:00:00 2001 From: Hai Zheng Date: Wed, 27 Dec 2023 15:51:58 -0500 Subject: [PATCH] v6.1-a6 in dev: Detect set_time_limit availability b4 set --- src/img-optm.cls.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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