PHP 8.5.0 Alpha 2 available for testing

fsync

(PHP 8 >= 8.1.0)

fsyncSincroniza los cambios realizados en el fichero (incluyendo los metadatos)

Descripción

fsync(resource $stream): bool

Esta función sincroniza los cambios realizados en el fichero, incluyendo sus metadatos. Es similar a fflush(), pero además solicita al sistema operativo que escriba en el soporte de almacenamiento.

Parámetros

stream

El puntero de archivo debe ser válido y apuntar a un archivo abierto con éxito por fopen() o fsockopen() (y no cerrado aún por fclose()).

Valores devueltos

Esta función retorna true en caso de éxito o false si ocurre un error.

Ejemplos

Ejemplo #1 Ejemplo de fsync()

<?php
$file
= 'test.txt';
$stream = fopen($file, 'w');
fwrite($stream, 'test data');
fwrite($stream, "\r\n");
fwrite($stream, 'additional data');
fsync($stream);
fclose($stream);
?>

Ver también

  • fdatasync() - Sincroniza los datos (pero no los metadatos) con el fichero
  • fflush() - Envía todo el contenido generado en un fichero

add a note

User Contributed Notes 1 note

up
9
Dave Gebler
3 years ago
Two points worth noting:

1. fsync() is not suitable for high throughput, use it only when the durability of a file write really matters to you.

2. fsync() includes an implicit call to fflush() so you don't need to manually flush before you sync.
To Top