What is the best strategy to debug a "Fatal error: Allowed memory size of 268435456 bytes exhausted " error? This error i'm getting is strange and something is obviously wrong. The function which is causing it is
/**
* Flush all output buffers for PHP 5.2.
*
* Make sure all output buffers are flushed before our singletons our destroyed.
*
* @since 2.2.0
*/
function wp_ob_end_flush_all() {
$levels = ob_get_level();
for ($i=0; $i<$levels; $i++)
ob_end_flush();
}
i simply rebased some code i was working on and started getting this. what's your strategy to debug this?
You can find the php. ini file in the public_html for your website and right-click on the file to Edit it. Look for the line defining the memory_limit variable and set the value accordingly. Then, save the changes and reload your site to see if the PHP “Allowed Memory Size of Bytes Exhausted” error has been resolved.
The correct way is to edit your php. ini file. Edit memory_limit to your desire value. As from your question, 128M (which is the default limit) has been exceeded, so there is something seriously wrong with your code as it should not take that much.
If you've been getting an error that says “Fatal error: Allowed memory size of x bytes exhausted”, that means either your server is limiting the amount of memory used by your website or a plugin is consuming too much server memory.
Try the below code, if your code reaches the specified number of bytes it just echo it and exit. instead of crashing :
function wp_ob_end_flush_all() {
$levels = ob_get_level();
for ($i=0; $i<$levels; $i++){
ob_end_flush();
if(memory_get_peak_usage() > 268435400) { // 268435456
echo memory_get_peak_usage(). ' reached! now we should stop the script.' ;
break; // or die();
}
}
}
Update
To answer your question, one way to debug leaking is to use xdebug another way it to use the function I gave in the example or wrap your suspicious functions by memory_get_usage
and compare the difference.
I was also getting this error upon starting the Apache server with EasyPhp-Devserver-16.1.
In my case, it was because Easy php was trying to load a too large error.log file.
Deleting the old server log in
C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-binaries\httpserver\apache2418x160331124251\logs
and creating an empty one solved my problem.
Hope this can help others.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With