PHP memory exhaustion – Device_Cache.php
-
Hi Ben,
While investigating an unrelated WordPress update failure this morning, I came across four identical PHP fatal errors in our Apache error log:
PHP Fatal error: Allowed memory size of 134217728
bytes exhausted (tried to allocate 2097152 bytes)
in /wp-content/plugins/independent-analytics/
IAWP/Utils/Device_Cache.php on line 68
For reference, here's what we're running:
IA version 2.16.3
Debian 13
Apache 2
PHP-FPM 8.4.28 (upgraded from 8.4.27 this morning)
WordPress 7.1.5 (Multisite)
PHP memory limit of 128 MB
I had a look at line 68 of Device_Cache.php:
$data = json_decode($json, \true);
That prompted me to check the size of our device-detector.json file, which, to my surprise, was 7 MB and contained only 122 top-level entries.
I then ran a little PHP test outside of WordPress to see how much memory was being consumed simply by reading and decoding the file.
Results were:
Initial memory: 389984 bytes
After reading: 7664656 bytes
After decoding: 69159544 bytes
Peak memory: 69159640 bytes
That's approximately 66 MB of memory without even loading WordPress or any of its plugins!
We've also been dealing with what appears to be distributed bot traffic lately and have implemented rate limiting on our upstream firewall. I don't know if that traffic has contributed to the growth of the cache, but I thought it was worth mentioning.
Looking at the code, I also couldn't see anything within the class that would limit the size of the cache or expire individual entries.
Is this something you would have expected?
Rather than simply increasing the PHP memory limit, I thought I'd run this by you first. I've left the cache intact in case there's anything else you'd like me to look at.
Thanks!
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.