ScorpioTiger Posted December 22, 2020 Share Posted December 22, 2020 I'm suddenly getting 500 server errors on a WordPress site. In the logs I'm getting; PHP message: PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 68262447988 bytes) in /var/www/mysite.com/wp-includes/load.php on line 1357 That's 68 Gig that it's trying to allocate. Clearly this is a spurious message as nothing on the site is doing anything that requires anything like this much memory. I can restart PHP and load the page fine. When I try to refresh the page to load a second time, I get the error. It's the same regardless of the page I request. Always works first time, fails subsequent times. What could be causing this? Quote Link to comment https://forums.phpfreaks.com/topic/311913-allowed-memory-exhaustedtried-to-allocate/ Share on other sites More sharing options...
Barand Posted December 22, 2020 Share Posted December 22, 2020 (edited) The most common cause I've experienced is a recursive process with no working exit strategy - infinite recursion. Edited December 22, 2020 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/311913-allowed-memory-exhaustedtried-to-allocate/#findComment-1583329 Share on other sites More sharing options...
ScorpioTiger Posted December 22, 2020 Author Share Posted December 22, 2020 6 minutes ago, Barand said: The most common cause I've experienced is a recursive process with no working exit strategy - infinite recursion. I did have the thought of recursion. The error response from the server is almost immediate, and it doesn't explain why identical requests can succeed the first time and fail the second. Quote Link to comment https://forums.phpfreaks.com/topic/311913-allowed-memory-exhaustedtried-to-allocate/#findComment-1583330 Share on other sites More sharing options...
Barand Posted December 22, 2020 Share Posted December 22, 2020 (edited) It can happen very quickly... recurse(0); function recurse($level) { if ($level == 20) return; // then comment out this line and try again recurse($level+1); } Edited December 22, 2020 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/311913-allowed-memory-exhaustedtried-to-allocate/#findComment-1583334 Share on other sites More sharing options...
Barand Posted December 22, 2020 Share Posted December 22, 2020 1 hour ago, ScorpioTiger said: and it doesn't explain why identical requests can succeed the first time and fail the second. Could be your exit condition isn't being met sometimes. In the above, call recurse(30) instead of recurse(0) so that the level is never 20. Quote Link to comment https://forums.phpfreaks.com/topic/311913-allowed-memory-exhaustedtried-to-allocate/#findComment-1583335 Share on other sites More sharing options...
ScorpioTiger Posted December 22, 2020 Author Share Posted December 22, 2020 I've done some more troubleshooting and the problems goes away if I disable opcache in php.ini. So it would appear that something is failing in a less than graceful way. I'll start testing increasing memory for opcache and see what difference it makes. To anyone else seeing this strange behaviour whereby a page loads successfully the first time, but not subsequent times, try disabling opcache and see if the problem goes way; if so, you know where to look. Quote Link to comment https://forums.phpfreaks.com/topic/311913-allowed-memory-exhaustedtried-to-allocate/#findComment-1583339 Share on other sites More sharing options...
requinix Posted December 22, 2020 Share Posted December 22, 2020 The other common reason for PHP trying to allocate absurd amounts of memory is, unfortunately, a PHP bug. Exactly which version are you using? Was it upgraded recently? Quote Link to comment https://forums.phpfreaks.com/topic/311913-allowed-memory-exhaustedtried-to-allocate/#findComment-1583341 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.