0

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!

6 Answers 6

5

Not sure about performance but you can use

php -q myscript.php > /dev/null
Sign up to request clarification or add additional context in comments.

Comments

2

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.

1 Comment

That's why I proposed dummy ob_esity that devours all output before it hits the buffer.
1
fclose(STDOUT);

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

Comments

0

Using > /dev/null is not enough?

Comments

0

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.

Comments

0
function ob_esity($b) { return ''; }
ob_start('ob_esity');

1 Comment

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 ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.