PHP suddenly stops before it's done

elleryjh

Well-Known Member
Apr 12, 2003
475
0
166
Running PHP 5.3.2 (cli) (built: Apr 30 2010 07:29:33)
Using suPHP.
REDHAT Enterprise 5.5 i686 standard

I have a particular PHP script (uses the Smarty template engine) which has a problem: after running a bunch of PHP code, it dies without warning. Putting trace echos in the code seems to fix the problem by holding off the exiting, however.

If nothing is output before the death occurs, it gives a premature end of script headers / 500 Internal Server Error.

For example:

Code:
doSomething1();
doSomething2();
doSomething3();  // quits here!
doSomething4();
doSomething5();

Code:
doSomething1();
echo " 1 ";
doSomething2();
echo " 2 ";
doSomething3();
doSomething4();// quits here!
doSomething5();
Code:
doSomething1();
echo " 1 ";
doSomething2();
echo " 2 ";
doSomething3();
echo " 3 ";
doSomething4();
echo " 4 ";
doSomething5();// quits here!
So, I am able to fix the problem by adding "echo ' n ';" every 50 lines or so. But if I do not, it stops in the middle of output.

So it's as if PHP exits if nothing's been output for x clock cycles.

I have tried to modify PHP's max execution time (set_time_limit), memory limit, all with no effect.

There is no error output by PHP when it dies (even using E_ALL).

Seems to be limited to this one script, though much longer than most (903LOC).

It doesn't seem to be segfaulting, as there is no core file generated.
 

elleryjh

Well-Known Member
Apr 12, 2003
475
0
166
Solved? I was able to stop the problem by turning on output buffering. Still not an explanation for what is happening, but at least it's a workaround.