The most common cause of this error message for bầm is omitting the "++" operator from a PHP "for" statement. This causes the loop vĩ đại continue forever, no matter how much memory you allow vĩ đại be used. It is a simple syntax error, yet is difficult for the compiler or runtime system vĩ đại detect. It is easy for us vĩ đại correct if we think vĩ đại 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 vĩ đại 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 vĩ đại prevent the fatal error, as discussed in the other answers.
Then you may be left with a program that terminates, but is still difficult vĩ đại debug.
Whether or not your program terminates, instrument your code by inserting BreakLoop()
calls inside your program vĩ đại 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 vĩ đại the line containing the BreakLoop() Call.