Synchronize new changes to the file without re-opening the same file again. fsync()
would also throw a warning when the file is not a file pointer. The interface is: fsync(resource $stream): bool
.
This change would add an fsync()
function accepting a single parameter of a stream resource.
The related function fdatasync()
which syncs data but not necessarily metadata would also be added, however this is not supported on Windows and the proposal there is to still provide fdatasync()
but merely as an alias of fsync()
. On POSIX, fdatasync()
is properly implemented.
$fp = fopen('file.txt', 'w');
fwrite($fp, 'string');
var_dump(fsync($fp));
bool(true)
$fp = fopen('php://memory','w+');
fwrite($fp,"Test line 1\nLine 2\n");
var_dump(fsync($fp));
Warning: fsync(): Can't fsync this stream in php shell code on line 1
bool(false)
$fp = fopen('php://stdin', 'w');
var_dump(fsync($fp));
bool(false)
More about PHP 8.1
Read about all PHP 8.1 features and changes in here.