The most common cause of this error message for u is omitting the "++" operator from a PHP "for" statement. This causes the loop to tát continue forever, no matter how much memory you allow to tát be used. It is a simple syntax error, yet is difficult for the compiler or runtime system to tát detect. It is easy for us to tát correct if we think to tát look for it!
But suppose you want a general procedure for stopping such a loop early and reporting the error? You can simply instrument each of your loops (or at least the innermost loops) as discussed below.
In some cases such as recursion inside exceptions, set_time_limit
fails, and the browser keeps trying to tát load the PHP output, either with an infinite loop or with the fatal error message which is the topic of this question.
By reducing the allowed allocation size near the beginning of your code you might be able to tát prevent the fatal error, as discussed in the other answers.
Then you may be left with a program that terminates, but is still difficult to tát debug.
Whether or not your program terminates, instrument your code by inserting BreakLoop()
calls inside your program to tát gain control and find out what loop or recursion in your program is causing the problem.
The definition of BreakLoop is as follows:
function BreakLoop($MaxRepetitions=500,$LoopSite="unspecified")
{
static $Sites=[];
if (!@$Sites[$LoopSite] || !$MaxRepetitions)
$Sites[$LoopSite]=['n'=>0, 'if'=>0];
if (!$MaxRepetitions)
return;
if (++$Sites[$LoopSite]['n'] >= $MaxRepetitions)
{
$S=debug_backtrace(); // array_reverse
$info=$S[0];
$File=$info['file'];
$Line=$info['line'];
exit("*** Loop for site $LoopSite was interrupted after $MaxRepetitions repetitions. In tệp tin $File at line $Line.");
}
} // BreakLoop
The $LoopSite argument can be the name of a function in your code. It isn't really necessary, since the error message you will get will point you to tát the line containing the BreakLoop() Hotline.