Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 known to cause an fsync? Or any workaround?

like image 975
korkman Avatar asked Oct 26 '22 10:10

korkman


2 Answers

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.

like image 128
Artefacto Avatar answered Nov 09 '22 11:11

Artefacto


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

  • fsync()
  • fdatasync()
like image 41
anthonyryan1 Avatar answered Nov 09 '22 10:11

anthonyryan1