8

What are the methods to turn on output buffering either within a PHP script or using and htaccess file?

I use the following method in an htaccess file in the root of my application:

php_value output_buffering On
php_value output_handler mb_output_handler

On one of my shared hosting accounts (linux hosting with PHP 5.2.x), the above yields a blank page. Tech support says they can't turn it on in the php.ini file but I can turn it on in my script...

ob_start() and ob_end_flush() also yields the same result. What can I do?

3
  • 1
    If you get blank pages, look into the error.log. Did you set an output encoding before activating the mb_output_handler? Commented Jan 6, 2011 at 23:14
  • @mario, no, i didn't know i had to. how can i do that? Commented Jan 6, 2011 at 23:21
  • 2
    If you want this deleted, please flag it for moderator attention (as I just did). Kindly, stop rolling this back, it just puts nonsense on our front page :( Commented Jan 22, 2011 at 0:18

2 Answers 2

7

Use ob_start() and ob_end_flush().

ob_start() at the start of the script before any output (not even an empty space).

When u want to output use ob_end_flush().

Sign up to request clarification or add additional context in comments.

4 Comments

2nd time ive seen this today. You can turn on output buffering AFTER or BEFORE printing content. It makes no difference. ideone.com/URuKl
Sure it makes a difference. If you print something without output buffering turned on, it will actually be output.
@klinky i was not trying to demonstrate ob, i was demonstrating that you can call it at any point, not just at the start before any output, as predrag.music stated.
@jw it makes a difference, but its not going to break it and not work, which seems like what he was implying. I think people get it confused with calling the header function, because often people will use output buffer to make sure they can use the header function.
2

Check your PHP.ini file and ensure the Output Buffer is enabled.

After that, you can use ob_start() whenever you want to begin buffering and ob_flush() to flush the buffer whenever you want to stop buffering.

4 Comments

If you use cPanel (most hosts do), there is an option in there to change the php.ini configurations.
FYI Scott, I use hostmonster.com, which is shared hosting, and I can still edit my own php.ini file.
@justinl, i know what you mean, on most of my account i can do the same - not all however.
that's unfortunate :S I'm not sure why those other methods aren't working for you

Your Answer

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