fsync() does not *guarantee* data has been persisted because no software
mechanism which exists can do that. It is however the *best assurance* we
can have that data has been physically persisted by the time the function
returns.

fsync() is the best operating-system level assurance we can get regarding
data persistence and PHP is the only major programming language I can think
of which doesn't support a means of doing it. I've had use cases in web
systems and microservices written in PHP where the ability to provide
durable file writes would have been very valuable, other cases where
services have had to be written in Java or some other language specifically
because they require durability where PHP might otherwise have been a good
candidate.

> While there is little reason not to add fsync() to PHP the importance and
benefits are IMHO not that big.

Arguably so, but neither that big is the effort required to implement this
feature.

On Mon, Jun 1, 2020 at 8:47 PM Christian Schneider <cschn...@cschneid.com>
wrote:

> Am 01.06.2020 um 18:56 schrieb David Gebler <davidgeb...@gmail.com>:
> > It seems to me an odd oversight that this has never been implemented in
> PHP
> > and means PHP has no way to perform durable file write operations, making
> > it inherently unsuitable for any systems requiring more intensive I/O,
> > mission critical logs, auditing, etc.
>
> I think there is a misconception of the usefulness of fsync() here.
>
> First of all it does not *really* guarantee the data is safe from power
> outages etc, see
>         https://stackoverflow.com/a/706688
>         https://stackoverflow.com/a/725742
> and other answers in that thread.
>
> Secondly I'd rather rely on something like a proper DB if not losing any
> data is crucial.
> Trying to implement it in pure PHP and plain old files seems like using
> the wrong tools for the job to me.
>
> While there is little reason not to add fsync() to PHP the importance and
> benefits are IMHO not that big.
>
> - Chris
>
>

Reply via email to