I want to change the buffer size for file IO while reading/writing to files from PHP, but the only way to do so is stream_set_write_buffer()
which always return -1. I couldn’t find any error descriptions with error_reporting(E_ALL);
or whatever.
I have a live example that reproduces the problem:
https://onlinephp.io/c/5955f
I am asking for help, why does it fail? How to make it work and what am I missing? No docs helped me so far.
2
Answers
Here is a workaround:
Why does it fail?
stream_set_write_buffer
sets the buffer throughsetvbuf
But PHP’s
fopen
function doesn’t call C’sfopen
function, but instead calls theopen
system call, which returns a file descriptor, so thisfile
field is a null:Then I searched this file and found a function called
php_stdiop_cast
that sets thefile
field:And this function is called by another function called
php_stdiop_sync
, which is the implementation offsync
andfdatasync
functions.Based on your sandbox/online environment:
Why
stream_set_write_buffer()
might failStream types and their support
php://output
php://stdout