Errors, redirecting, and output buffering...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Errors, redirecting, and output buffering...

Post 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)
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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...
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Hmm if I start output it triggers, so it seems that its treating errors differently than output.
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

Wouldn't it be easier just to write code without any errors in it.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post 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....
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post 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.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply