Skip to content

moehman/PhpOutputBuffer

Repository files navigation

output_buffer – PHP Stream Filter Extension

Buffers write operations on any PHP stream, reducing syscall overhead exactly as ob_start() does for output – but for arbitrary streams.

Requirements

  • PHP 8.0 or higher
  • php-dev / php-devel package
  • Standard C build tools (gcc / clang, make, autoconf)

Build (Linux / macOS)

cd output_buffer_ext/
phpize
./configure --enable-output_buffer
make
sudo make install          # installs output_buffer.so into the PHP ext dir

Add to php.ini:

extension=output_buffer

Build (Windows)

Use the PHP SDK and run:

buildconf
configure --enable-output_buffer=shared
nmake

Usage

No stream_filter_register() call needed – the filter is registered automatically when the extension loads.

$fp = fopen('output.txt', 'w');

// default 4 KB buffer
stream_filter_append($fp, 'output.buffer');

// custom 8 KB buffer
stream_filter_append($fp, 'output.buffer', STREAM_FILTER_WRITE, 8192);

for ($i = 0; $i < 10000; $i++) {
    fwrite($fp, 'x');     // ~3 real writes instead of 10 000
}

fclose($fp);              // remaining bytes flushed automatically

fflush($fp) is also supported – the buffer is flushed immediately.

Filter name

output.buffer

File overview

File Purpose
output_buffer.c Extension implementation
php_output_buffer.h Header / type definitions
config.m4 Linux/macOS build config
config.w32 Windows build config

Changelog

Version Notes
1.0.0 Initial release

About

PHP stream filter extension that does output buffering

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors