PHP Output Buffering Check? [duplicate]
Asked Answered
G

2

3

Possible Duplicate:
PHP - How Detect if Output Buffering is Turned On

How can I check in PHP if output_buffering is set to On? I have to troubleshoot a site and I have no access to the hosting panel.

Something like:

if(output_buffering == 'On')
{
    echo 'It is On';
}
else
{
    echo 'It is NOT On';
}

Thank you!

Goahead answered 31/3, 2011 at 21:12 Comment(0)
F
2

You should be able to do this with ini_get(). I didn't test it, but I am pretty sure it will suit your needs since ini_get() is used for that purpose: checking php.ini options.

Fraud answered 31/3, 2011 at 21:15 Comment(3)
It should work to be tested with if(ini_get('output_buffering')) { echo 'it is on'; }Fraud
How about if you start output buffering from within your script? ini_get('output_buffering') => false; ob_start(); ini_get('output_buffering') => false;Hydromancy
The question is about the php.ini setting as you can see. Anyhow, in the situation you specified, Wrikken answer is surely golden!Fraud
S
11
if(ob_get_level() > 0){
   //there are some buffers active.
}


$ php -d output_buffering=1 -r'var_dump(ob_get_level());'
int(1)
$ php -d output_buffering=0 -r'var_dump(ob_get_level());'
int(0)

It does however check whether there is an output buffer active, not what the actual setting of PHP itself is. A manual ob_start() (or more then one) will also increase the level. Usually this is more interesting then the actual output_buffering setting. If you actually need that, fo with the ini_get answer.

Sump answered 31/3, 2011 at 21:15 Comment(0)
F
2

You should be able to do this with ini_get(). I didn't test it, but I am pretty sure it will suit your needs since ini_get() is used for that purpose: checking php.ini options.

Fraud answered 31/3, 2011 at 21:15 Comment(3)
It should work to be tested with if(ini_get('output_buffering')) { echo 'it is on'; }Fraud
How about if you start output buffering from within your script? ini_get('output_buffering') => false; ob_start(); ini_get('output_buffering') => false;Hydromancy
The question is about the php.ini setting as you can see. Anyhow, in the situation you specified, Wrikken answer is surely golden!Fraud

© 2022 - 2024 — McMap. All rights reserved.