PHP ob_get_status() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Output Control

Definition

In PHP, ob_get_status() returns an array of status details about the active output buffer, or about every active buffer when full status is requested.

With the default false, you get one associative array for the top buffer (name, type, flags, level, chunk_size, buffer_size, buffer_used). With true, you get a numeric list of those arrays, one per nesting level. With no buffering, you get an empty array.

Syntax

Call ob_get_status() with the values you need. Start with this line.

PHP
$info = ob_get_status();
CallWhat it does
ob_get_status()Status array for the top active buffer, or [] if none.
ob_get_status(true)List of status arrays for every nested buffer.
ob_get_status()['buffer_used']Bytes currently stored, same idea as ob_get_length().

The "level" key inside the status array is zero-based. The first buffer has status level 0, while ob_get_level() reports 1 for that same buffer. "name" is usually "default output handler" for a plain ob_start().

Library declarations
PHP
ob_get_status(bool $full_status = false): array

Parameters

ParameterDescription
full_statusOptional. false (default) returns only the top buffer. true returns status for every active nesting level.

Return Value

Return ValueDescription
arrayOne status array for the top buffer, a list of status arrays when full_status is true, or an empty array when buffering is off.

PHP Examples

Example 1 — Read Top Buffer Status

Start a buffer, echo a short string, and print a few useful status fields.

PHP
<?php
ob_start();
echo "Hi";
$s = ob_get_status();
ob_end_clean();
echo $s['name'], " used=", $s['buffer_used'], " level=", $s['level'], PHP_EOL;

How It Works

  1. ob_start() begins a default output handler buffer.
  2. echo stores two characters, so buffer_used is 2.
  3. status level is 0 for the first buffer (zero-based).
  4. ob_end_clean() ends the buffer after we copy the fields we need.

Example 2 — Full Status for Nested Buffers

Open two buffers and use full status to count them and read each name.

PHP
<?php
ob_start();
ob_start();
$all = ob_get_status(true);
ob_end_clean();
ob_end_clean();
echo "count=", count($all), PHP_EOL;
echo "0:", $all[0]['name'], " 1:", $all[1]['name'], PHP_EOL;

How It Works

  1. Two nested ob_start() calls create two buffers.
  2. ob_get_status(true) returns an array with two entries.
  3. Index 0 is the outer buffer; index 1 is the inner top buffer.
  4. Both use the default handler name in this demo.

Example 3 — Empty Array When Buffering Is Off

Call ob_get_status() with no active buffer and show the empty result.

PHP
<?php
$off = ob_get_status();
ob_start();
$on = ob_get_status();
ob_end_clean();
echo "off=", var_export($off, true), PHP_EOL;
echo "on_used=", $on['buffer_used'], PHP_EOL;

How It Works

  1. With no buffer, ob_get_status() returns an empty array.
  2. ob_start() creates an empty active buffer.
  3. buffer_used is 0 because nothing was echoed yet.
  4. ob_end_clean() turns buffering off again.

Frequently Asked Questions

It returns status information about the active output buffer, or about all nested buffers when you pass true.
buffer_used is how many bytes of output are stored right now. buffer_size is how much memory is allocated for the buffer, which can be larger.
ob_get_status() uses a zero-based level. ob_get_level() counts active buffers starting at 1. They describe the same nesting with different numbering.
No output buffer is active. That is normal before the first ob_start() or after every buffer has been ended.
Call ob_get_status(true). You get a list of status arrays, one per level.

Next: ob_gzhandler()

ob_gzhandler() is a built-in callback for ob_start() that can gzip (or deflate) buffered o.

ob_gzhandler() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful