PHP ob_list_handlers() Function

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

Definition

In PHP, ob_list_handlers() returns an array of the names of every active output handler, from the outermost buffer to the innermost.

A plain ob_start() usually lists "default output handler". A callback passed to ob_start() appears as that callable's name. When nothing is buffering, the array is empty.

Syntax

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

PHP
$handlers = ob_list_handlers();
CallWhat it does
ob_list_handlers()Array of active handler names, or [] if none.
ob_start(); ob_list_handlers()Typically ["default output handler"].
ob_start('ob_gzhandler'); ob_list_handlers()Includes "ob_gzhandler" while that buffer is active.

Handler order matches nesting: earlier entries are outer buffers, later entries are deeper. Closures show up as "Closure::__invoke". This is a read-only inspection tool; it does not start or stop buffering.

Library declarations
PHP
ob_list_handlers(): array

Parameters

ParameterDescription
—This function takes no parameters.

Return Value

Return ValueDescription
arrayA list of handler name strings for each active output buffer, or an empty array when buffering is off.

PHP Examples

Example 1 — List the Default Handler

Start a plain buffer and print the single handler name.

PHP
<?php
ob_start();
$handlers = ob_list_handlers();
ob_end_clean();
echo $handlers[0], PHP_EOL;

How It Works

  1. ob_start() without a callback uses the default handler.
  2. ob_list_handlers() returns a one-element array.
  3. We print that name.
  4. ob_end_clean() ends the buffer.

Example 2 — List Nested Handlers

Start a default buffer and a callback buffer, then print both names.

PHP
<?php
ob_start();
ob_start(function ($chunk) {
    return $chunk;
});
$handlers = ob_list_handlers();
ob_end_clean();
ob_end_clean();
echo implode(" | ", $handlers), PHP_EOL;

How It Works

  1. The outer buffer is the default handler.
  2. The inner buffer is an anonymous function.
  3. ob_list_handlers() lists outer then inner.
  4. Closures are reported as Closure::__invoke.

Example 3 — Empty List When Buffering Is Off

Compare the handler list before and after starting a buffer.

PHP
<?php
$off = ob_list_handlers();
ob_start();
$on = ob_list_handlers();
ob_end_clean();
echo "off=", count($off), " on=", count($on), PHP_EOL;

How It Works

  1. With no buffer, the list length is 0.
  2. ob_start() adds one handler.
  3. The list length becomes 1.
  4. ob_end_clean() removes it again.

Frequently Asked Questions

It returns the names of all active output handlers, from outer buffers to inner ones.
Usually "default output handler".
The list shows that callable's name, such as a function name or Closure::__invoke.
No. It only reports handlers that are already active.
ob_list_handlers() is a simple list of names. ob_get_status() returns richer details such as buffer_used and flags.

Next: ob_start()

ob_start() turns on output buffering so echo and other output are stored instead of being .

ob_start() 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