CakeFest 2024: The Official CakePHP Conference

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

User Contributed Notes 1 note

up
0
greg at example dot com
7 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