rfc:fsync_function

This is an old revision of the document!


PHP RFC: fsync() function

Introduction

fsync() is a function similar to fflush(), however where fflush() only instructs the application to flush its internal buffers out to the OS, fsync() further instructs the OS to flush its buffers to physical storage, ensuring a completed and persisted write before returning any success. PHP provides plain stream wrappers for most common file system functions inherited from C and is indeed one of few major languages to not provide any interface to fsync. This RFC proposes implementing fsync in core.

Proposal

This RFC would add an fsync() function accepting a single parameter of a stream resource. The implementation of this function would be a thin wrapper around the standard C fsync (or equivalent _commit on Windows API, which uses an identical signature).

$fp = fopen('file.txt', 'w');
fwrite($fp, 'string');
var_dump(fsync($fp));
 
bool(true)

Backward Incompatible Changes

None.

Proposed PHP Version(s)

8.1

RFC Impact

To SAPIs

None, this function would be available in all SAPIs supporting plain stream wrappers.

To Existing Extensions

No.

Open Issues

Proposed Voting Choices

Accept RFC as proposed.

Patches and Tests

Implementation

References

rfc/fsync_function.1611967043.txt.gz · Last modified: 2021/01/30 00:37 by dwgebler