Skip to content

Commit

Permalink
v6.1-a6 in dev: Detect set_time_limit availability b4 set
Browse files Browse the repository at this point in the history
  • Loading branch information
Hai Zheng committed Dec 27, 2023
1 parent 9dc1ca2 commit e87af71
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/img-optm.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]');

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e87af71

Please sign in to comment.