8

Is there a simple way to detect in PHP if output_buffering is enabled in php.ini? I'd like to be able to display a message if it is not enabled.

Within my application I tried using an htaccess file to automatically enable it but it seems it does not work in all server environments and in some cases it gives a nasty error.

Thank you very much!

John
  • 1
  • 13
  • 98
  • 177
usnidorg
  • 83
  • 1
  • 1
  • 3
  • 2
    http://stackoverflow.com/questions/5506411/php-output-buffering-check –  Apr 10 '11 at 00:50

4 Answers4

21

You can access the output_buffering value in the php.ini file by doing:

var_dump(ini_get('output_buffering'));

But I think what you are looking for is ob_get_level() (or ob_get_status()):

var_dump(ob_get_level());

Returns the level of nested output buffering handlers or zero if output buffering is not active.

Alix Axel
  • 151,645
  • 95
  • 393
  • 500
7

You can check any INI setting in PHP with the ini_get method. http://php.net/ini_get

ini_get('output_buffering');

Likewise, you can change most INI settings with ini_set:

ini_set('output_buffering', 'on');
coreyward
  • 77,547
  • 20
  • 137
  • 166
1

simple

check by

echo ini_get('output_buffering');

or run a file calling phpinfo(); function it will list all veriables containing values check the value for 'output_buffering ' in list.

-4

I think you can go

if(!ob_start())
{
}
Craig White
  • 13,492
  • 4
  • 23
  • 36