What is PHP ob_get_status() function?
Using ob_get_status(), you can get to know status of your current (or top) output buffer level or all the active output buffer levels.
Syntax:
ob_get_status($full_status)
Parameters:
This function has only one optional parameter-
$full_status (Optional): If the value is set as TRUE, the function returns status information of all the levels from the calling output buffer to the lowest level of output buffer.
If the value is set as FALSE, the function only returnscurrent output level’s status.
Return Values:
The function returns one array for each output buffer’s level with the following keys-
Array
(
[name] =>
[type] =>
[flags] =>
[level] =>
[chunk_size] =>
[buffer_size] =>
[buffer_used] =>
)
Examples:
Example 1:
<pre>
<?php
print_r(ob_get_status());
?>
</pre>
Output:
Array
(
[name] => default output handler
[type] => 0
[flags] => 112
[level] => 0
[chunk_size] => 4096
[buffer_size] => 8192
[buffer_used] => 7
)
Explanation:
It is showing status of the output buffer status that is set in php.ini file.
Example 2:
<pre>
<?php
ob_start();
print_r(ob_get_status(TRUE));
ob_start();
?>
</pre>
Output:
Array
(
[0] => Array
(
[name] => default output handler
[type] => 0
[flags] => 112
[level] => 0
[chunk_size] => 4096
[buffer_size] => 8192
[buffer_used] => 24
)
[1] => Array
(
[name] => default output handler
[type] => 0
[flags] => 112
[level] => 1
[chunk_size] => 0
[buffer_size] => 16384
[buffer_used] => 0
)
)
Explanation:
The script has 3 levels of output buffer – The default php.ini’s output buffer level is the lowest one, next higher level is introduced by the ob_start() function in line 3 and the last ob_start() function introduces the highest level of output buffer in the script. But, as the ob_get_status() function is called from the first ob_start() function, the ob_get_status() function shows the status of the first 2 levels of output level – this one and the lower one in the php.ini file.
PHP Version Support:
PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8
Summary: PHP ob_get_status() Function
PHP ob_get_status() function is a built-in PHP function and part of the PHP’s Output Control functions.