PHP fdatasync() Function Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 Comment More infoAdvertise with us Next Article PHP | fstat( ) Function N neeraj3304 Follow Improve Article Tags : PHP PHP-function PHP-Filesystem Similar Reads PHP | fstat( ) Function The fstat() function in PHP is an inbuilt function which is used to return information about an open file. The file name is sent as a parameter to the fstat() function and it returns an array with the following elements : Numeric Associative Description 0 dev Device number 1 ino inode number* 2 mode 3 min read PHP | fstat( ) Function The fstat() function in PHP is an inbuilt function which is used to return information about an open file. The file name is sent as a parameter to the fstat() function and it returns an array with the following elements : Numeric Associative Description 0 dev Device number 1 ino inode number* 2 mode 3 min read PHP Array Functions Arrays are one of the fundamental data structures in PHP. They are widely used to store multiple values in a single variable and can store different types of data, such as strings, integers, and even other arrays. PHP offers a large set of built-in functions to perform various operations on arrays. 7 min read PHP Array Functions Arrays are one of the fundamental data structures in PHP. They are widely used to store multiple values in a single variable and can store different types of data, such as strings, integers, and even other arrays. PHP offers a large set of built-in functions to perform various operations on arrays. 7 min read PHP fpassthru( ) Function The fpassthru() function in PHP is an inbuilt function which is used to read data from a current position from a specified file until end of file and then write the result to the output buffer. The file which has to be read is sent as a parameter to the fpassthru() function and it returns the number 2 min read PHP fpassthru( ) Function The fpassthru() function in PHP is an inbuilt function which is used to read data from a current position from a specified file until end of file and then write the result to the output buffer. The file which has to be read is sent as a parameter to the fpassthru() function and it returns the number 2 min read Like