ob_start: Capturing STDOUT and STDERR

From: Date: Mon, 24 Mar 2008 01:08:19 +0000
Subject: ob_start: Capturing STDOUT and STDERR
Groups: php.general 
Request: Send a blank email to php-general+get-272021@lists.php.net to get a copy of this message
Hey There, I looked at the ob_start manual and found a segment of code that can be used to capture the output of a shell script and place it into a log file. One of the entries indicates this should work for both STDOUT and STDERR (29-Mar-2007). I wrote the following piece of code to test it out. function logger($buffer) { $handle = fopen('/var/log/test.log', 'a'); fwrite($handle, $buffer); fclose($handle); } ob_start("logger"); This will capture the output buffer until the shell terminates when the buffer is dumped to the test.log file. This is a simple mechanism and it works really well to keep STDOUT from going to the console and logging it. Unfortunately, STDERR continues to go to the console which is what I am working to avoid. I would like to capture STDOUT and STDERR using this technique. I am working to create a self contained script that does not rely on some external script to capture the output. The actual application needs to perform some post-processing of the output buffer at the end of the script. Any pointers in the correct direction would be helpful! Thanks, Greg

« previous php.general (#272021) next »