开发者

How to fsync or fdatasync in PHP?

PHP lacks any specific function to fsync on a file AFAIK. I do however feel the urge to fsync a logfile I am appending to from PHP.

Is there any native PHP function开发者_StackOverflow中文版 known to cause an fsync? Or any workaround?


I'm afraid it's not possible. The only reference to fsync in the sources is in the implementation of the flush operation for regular filesystem streams and it's just to explicitly say they're not fsyncing, only calling fflush.

If you really need this, you have to do it in a PHP extension.


As of PHP 8.1 these methods are now available with the expected names.

  • fsync()
  • fdatasync()


If you're dealing with a regular file, closing it with fclose will most likely commit your changes to disk. To assure that log messages hit the disk, just open and close the file for each write to your log.

Writes to the system log should take place immediately and are handled by the OS.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜