Open In App

PHP ob_get_status() Function

The ob_get_status() is an inbuilt function in PHP that is used for retrieving the status of the output buffer.

Syntax

ob_get_status(bool $full_status = false) : array

Parameter

This function accepts only one parameter which is described below.



Return Value

 The ob_get_status() function returns an array that contains all the information related to the output buffer.

Program 1: The following program demonstrates the ob_get_status() Function.






<?php
ob_start();
echo "This is content inside the buffer.";
$bufferStatus = ob_get_status();
print_r($bufferStatus);
ob_end_flush();
?>

Output:

This is content inside the buffer.Array
(
    [name] => default output handler
    [type] => 0
    [flags] => 112
    [level] => 0
    [chunk_size] => 0
    [buffer_size] => 16384
    [buffer_used] => 34
)

Program 2: The following program demonstrates the ob_get_status() Function.




<?php
if (ob_get_status()) {
    echo "Output buffering is active.";
} else {
    echo "Output buffering is not active.";
}
  
ob_start();
echo "This is content inside the buffer.";
  
if (ob_get_status()) {
    echo "Output buffering is still active.";
} else {
    echo "Output buffering is no longer active.";
}
ob_end_flush();
?>

Output:

Output buffering is not active. This is content inside the buffer.Output buffering is still active.    

Reference: https://www.php.net/manual/en/function.ob-get-status.php


Article Tags :