php8.5
Home/ Manual/ filesystem / functions/ fsync

fsync

PHP function Edit on GitHub ✎

(PHP 8 >= 8.1.0)

Synchronizes changes to the file (including meta-data)

Description

fsync(resource $stream): bool

This function synchronizes changes to the file, including its meta-data. This is similar to fflush(), but it also instructs the operating system to write to the storage media.

Parameters

stream

All

Return Values

Success

Examples

fsync() example

php
<?php

$file = 'test.txt';

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

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

See Also

Source: reference/filesystem/functions/fsync.xml · from the official PHP manual (php/doc-en)