Buffers write operations on any PHP stream, reducing syscall overhead
exactly as ob_start() does for output – but for arbitrary streams.
- PHP 8.0 or higher
php-dev/php-develpackage- Standard C build tools (gcc / clang, make, autoconf)
cd output_buffer_ext/
phpize
./configure --enable-output_buffer
make
sudo make install # installs output_buffer.so into the PHP ext dirAdd to php.ini:
extension=output_bufferUse the PHP SDK and run:
buildconf
configure --enable-output_buffer=shared
nmakeNo 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 automaticallyfflush($fp) is also supported – the buffer is flushed immediately.
output.buffer
| 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 |
| Version | Notes |
|---|---|
| 1.0.0 | Initial release |