PHP fdatasync() Function
Last Updated :
07 May, 2023
The fdatasync() function is an inbuilt function in PHP that is used to synchronize changes to a file’s data with the underlying storage device. This function is similar to the fsync() function, but it only synchronizes the file’s data, not its metadata.
Syntax:
bool fdatasync(resource $stream)
Parameters: This function takes one parameter which is described below:
- $stream: A file pointer resource that was obtained using the fopen() function.
Return Value: The fdatasync() function returns true if the synchronization was successful otherwise it will return false.
Example 1: The following program demonstrates the fdatasync() function.
PHP
<?php
$fp = fopen ( 'example.txt' , 'w' );
fwrite( $fp , 'Hello, world!' );
if (fdatasync( $fp )) {
echo "Changes to the file's data were successfully synchronized." ;
} else {
echo "Failed to synchronize changes to the file's data." ;
}
fclose( $fp );
?>
|
Output:
Changes to the file's data were successfully synchronized.
Example 2: The following program demonstrates the fdatasync() function.
PHP
<?php
$fp = fopen ( 'example.txt' , 'w' );
fwrite( $fp , 'Hello, world!' );
fdatasync( $fp );
fclose( $fp );
echo "Changes to the file's data were successfully synchronized." ;
?>
|
Output:
Changes to the file's data were successfully synchronized.
Reference: https://www.php.net/manual/en/function.fdatasync.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...