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
11.9k11 gold badges90 silver badges156 bronze badges
asked Apr 10, 2011 at 0:43
1
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.
answered Apr 10, 2011 at 0:49
Alix AxelAlix Axel
148k91 gold badges390 silver badges493 bronze badges
You can check any INI setting in PHP with the
ini_get
method. //php.net/ini_get
ini_get['output_buffering'];
Likewise, you can change most INI settings with ini_set
:
ini_set['output_buffering', 'on'];
answered Apr 10, 2011 at 0:50
coreywardcoreyward
74.6k19 gold badges133 silver badges159 bronze badges
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.
answered Apr 10, 2011 at 0:49
0
I think you can go
if[!ob_start[]]
{
}
answered Apr 10, 2011 at 0:47
Craig WhiteCraig White
12.9k4 gold badges22 silver badges35 bronze badges
0
[PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8]
ob_get_status — Get status of output buffers
Description
ob_get_status[bool $full_status
= false
]: array
Parameters
full_status
true
to return all active output buffer levels. If false
or not set, only the top level output buffer is returned.
Return Values
If called without the full_status
parameter or with full_status
= false
a simple array with the following elements is returned:
Array [ [level] => 2 [type] => 0 [status] => 0 [name] => URL-Rewriter [del] => 1 ]Simple ob_get_status[] results
level | Output nesting level |
type | 0 [internal handler] or 1 [user supplied handler]
|
status | One of PHP_OUTPUT_HANDLER_START [0], PHP_OUTPUT_HANDLER_CONT [1] or PHP_OUTPUT_HANDLER_END [2]
|
name | Name of active output handler or ' default output handler' if none is set |
del | Erase-flag as set by ob_start[] |
If called with full_status
= true
an array with one element for each active output buffer level is returned. The output level is used as key of the top level array and each array element itself is another array holding status information on one active output level.
Array [ [0] => Array [ [chunk_size] => 0 [size] => 40960 [block_size] => 10240 [type] => 1 [status] => 0 [name] => default output handler [del] => 1 ] [1] => Array [ [chunk_size] => 0 [size] => 40960 [block_size] => 10240 [type] => 0 [buffer_size] => 0 [status] => 0 [name] => URL-Rewriter [del] => 1 ] ]
The full output contains these additional elements:
Full ob_get_status[] resultschunk_size | Chunk size as set by ob_start[] |
size | ... |
blocksize | ... |
See Also
- ob_get_level[] - Return the nesting level of the output buffering mechanism
- ob_list_handlers[] - List all output handlers in use
rmagalhaess at hotmail dot com ¶
5 years ago
The fields inside the array returned by ob_get_status[] are:
Array
[
[name] => default output handler
[type] => 0
[flags] => 112
[level] => 1
[chunk_size] => 0
[buffer_size] => 16384
[buffer_used] => 0
]
These values are filled just after the function ob_start[]