Page 1 of 1

Errors, redirecting, and output buffering...

Posted: Tue Aug 16, 2005 8:28 pm
by nielsene
I have some scripts that generate errors, but redirect (ie the scripts don't generate the dreaded headers already sent). It seems to only happen with NOTICE level errors. So I guess that PHP is output buffering the errors in some manner, is there anyway to stop this behavoir? (Short of my adding die() before the redirects for debugging use)

Posted: Tue Aug 16, 2005 9:18 pm
by Ambush Commander
Hmm... it might be a configuration thing: php.ini has the ability to automatically turn on output buffering.

Other ways of testing it out is set your own error handler...

Posted: Tue Aug 16, 2005 9:30 pm
by nielsene
Hmm if I start output it triggers, so it seems that its treating errors differently than output.

Posted: Wed Aug 17, 2005 6:10 am
by bokehman
Wouldn't it be easier just to write code without any errors in it.

Posted: Wed Aug 17, 2005 8:57 am
by nielsene
I try to. But when I fail I like to know that I failed and be able to fix it. That's why I develop with E_ALL and error_reporting on. And its why it annoys me if PHP decides to hide the errors from me....

Posted: Wed Aug 17, 2005 9:05 am
by feyd
I've ran into a few instances where I could echo just barely before I used a header() and it'd go through.. so there's definitely some buffering going on at times.

Posted: Wed Aug 17, 2005 9:57 am
by bokehman
If you want to be certain there is no buffering switch off output buffering in php.ini. Also switch on implicit_flush. You could put all this in an included function with error reporting so you don't need to alter php.ini just include the function at the start of the script. Then after every echo add flush(). This way you can be certain there is no buffering by php.

Posted: Wed Aug 17, 2005 10:00 am
by nielsene
I've tried with implict flush on (and off). No change. There are no echo's to flush only the error's generated by PHP. I've tried adding a call to flush() before the header(), no change.

Posted: Wed Aug 17, 2005 10:03 am
by feyd
I've found that the output buffering of the server can do this too, unfortunately, most of us don't have control enough to turn off that "feature" in servers.. so at times, it's entirely unavoidable.