tags:

views:

169

answers:

6

Hi, i've got a php script that runs on the command line. To improve it's performance, i would like to completely suppress it's output.

How can I do that?

Thanks!

A: 
function ob_esity($b) { return ''; }
ob_start('ob_esity');
Michael Krelin - hacker
I dont think this will help with performance
Cem Kalyoncu
Neither I do. Well, maybe a bit. It sure will not buffer anything. I'd go for redirecting output myself, but that wouldn't comply with `php` tag ;-)
Michael Krelin - hacker
+5  A: 

Not sure about performance but you can use

php -q myscript.php > /dev/null
Cem Kalyoncu
I'd be interested to know the performance gain, if any.
Mike B
+2  A: 

One way would be to call ob_start() to turn on output buffering, and periodically call ob_clean() if you really don't want the output (or use a dummy ob_start() callback which does nothing).

Not sure how much of a performance gain this would be, as internally, PHP is still processing the output, except it goes into a buffer rather than to stdout.

If you've got a lot of diagnostic output you want to prevent, than it might be more effective to refactor your code to allow that to be suppressed by an application option.

Paul Dixon
That's why I proposed dummy ob_esity that devours all output before it hits the buffer.
Michael Krelin - hacker
A: 

Using > /dev/null is not enough?

igustin
A: 

If you have access to the script replace all echo with //echo. Perfect performance increase, but you will need to check multi-line echo statements.

Cem Kalyoncu
A: 
fclose(STDOUT);

This will work cross platform as the first line in the PHP script.

scragar