PHP Velho Oeste 2024

fdatasync

(PHP 8 >= 8.1.0)

fdatasyncデータをファイルに同期する(但しメタデータは除く)

説明

fdatasync(resource $stream): bool

この関数は、 stream の内容をストレージに同期します。 fsync() に似ていますが、ファイルのメタデータは同期しません。 この点だけが、POSIX システムで唯一異なることに注意して下さい。 Windows では、この関数は fsync() のエイリアスになっています。

パラメータ

stream

ファイルポインタは、有効なファイルポインタである必要があり、 fopen() または fsockopen() で正常にオープンされた (そしてまだ fclose() でクローズされていない) ファイルを指している必要があります。

戻り値

成功した場合に true を、失敗した場合に false を返します。

例1 fdatasync() の例

<?php

$file
= 'test.txt';

$stream = fopen($file, 'w');
fwrite($stream, 'test data');
fwrite($stream, "\r\n");
fwrite($stream, 'additional data');

fdatasync($stream);
fclose($stream);
?>

参考

  • fflush() - 出力をファイルにフラッシュする
  • fsync() - データをファイルに同期する(メタデータも含む)

add a note add a note

User Contributed Notes 1 note

up
-1
greg at example dot com
8 months ago
Does not flush st_atime, st_mtime or st_size.

If you need to use filesize after a write you will need need fsync() or fflush() instead.
To Top