phpday 2027 - Call for Papers

fsync

(PHP 8 >= 8.1.0)

fsync — Sincroniza los cambios realizados en el fichero (incluyendo los metadatos)

Descripción

function 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 fichero 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);
?>

Véase también

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

User Contributed Notes 1 note

up
15
Dave Gebler
5 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.
Adding new notes is disabled. Please see the links in the Found A Problem? section.
To Top