note 35893 added to function.ob-gzhandler

From: Date: Thu, 18 Sep 2003 11:54:00 +0000
Subject: note 35893 added to function.ob-gzhandler
Groups: php.notes 
Request: Send a blank email to php-notes+get-56686@lists.php.net to get a copy of this message
In the set_error_handler notes, there is a technique described for capturing all errors (even parse errors) before they are displayed the user, using a special error handler and output handler. If this output handler detects a fatal error in the output buffer, it's captured and dealt with before it can be displayed to the user. If no error was detected, then output buffer is displayed verbatim (i.e. without being compressed). If you are using this method, you can still take advantage of ob_gzhandler's compression. However, you MUST specify a mode argument (I'm using 4.2.2 on RedHat9). The mode value affects which headers are automatically added (Content-Encoding, etc). A value of '5' worked for me. '0' or discarding the argument produces a blank screen under Mozilla. <?php function my_output_handler(&$buffer) { // Detect errors in the output if(ereg("(error</b>:)(.+) in <b>(.+)</b> on line <b>(.+)</b>", $buffer, $regs)) { my_error_handler(E_ERROR, $regs[2], $regs[3], $regs[4]); // ... // ... Insert your error handling here ... // ... return 'An internal error occurred.'; } else { // The page rendered without any errors, so compress // and output. return ob_gzhandler($buffer, 5); } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.ob-gzhandler.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35893 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35893&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35893&report=yes

« previous php.notes (#56686) next »