Automattic / wp-memcached

Memcached Object Cache for WordPress.
https://wordpress.org/plugins/memcached/
GNU General Public License v2.0
157 stars 55 forks source link

Cron events cause PHP timeout #156

Open webd-uk opened 5 months ago

webd-uk commented 5 months ago

Hi,

We have a cron event that when run can occasionally take some time to complete, especially if previous instances have failed as there is more to do.

The site in question runs perfectly in all other aspects with object-cache.php installed however, we have since discovered that we see the following errors in debug.log ...

[19-Mar-2024 16:49:06 UTC] PHP Fatal error:  Maximum execution time of 30 seconds exceeded in /wp-content/object-cache.php on line 790
[19-Mar-2024 16:49:06 UTC] E_ERROR: Maximum execution time of 30 seconds exceeded in /wp-content/object-cache.php on line 790
[19-Mar-2024 16:52:56 UTC] PHP Fatal error:  Maximum execution time of 30 seconds exceeded in /wp-content/object-cache.php on line 790
[19-Mar-2024 16:52:56 UTC] E_ERROR: Maximum execution time of 30 seconds exceeded in /wp-content/object-cache.php on line 790
[19-Mar-2024 16:53:29 UTC] PHP Fatal error:  Maximum execution time of 30 seconds exceeded in /wp-content/object-cache.php on line 790
[19-Mar-2024 16:53:29 UTC] E_ERROR: Maximum execution time of 30 seconds exceeded in /wp-content/object-cache.php on line 790

When object-cache.php is deleted the issue no longer presents itself.

Why would having the object-cache.php installed introduce a PHP execution time limit?

Please advise.

Many thanks,

Oliver

webd-uk commented 4 months ago

As an update to this, we are trialing a fix whereby this is added before line 790 ...

if (defined('DOING_CRON')) {
    set_time_limit(0);
}
dd32 commented 2 months ago

This sounds like a cron task is reading/writing a lot of cache data, perhaps refreshing a cache, and the task simply runs into the limit during the write-to-cache section of code.

Debugging to determine why the time limit is being hit during that step, and determining if it's the fault of the object cache or other code, would be needed to move this forward.

I expect the reference of object-cache here is actually irrelevant to the originally reported problem.

webd-uk commented 1 month ago

Interesting. Except that you would think that the reading / writing a lot of cache data without a persistent object cache would take more time and be more likely to hit the PHP timeout. This is not the case and our fix above continues to resolve the issue.