问题
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!
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/5506411/php-output-buffering-check