PHP fdatasync() Function Last Updated : 28 Apr, 2025 Comments Improve Suggest changes 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 fdatasync() Function 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 | fgets( ) Function The fgets() function in PHP is an inbuilt function which is used to return a line from an open file. It is used to return a line from a file pointer and it stops returning at a specified length, on end of file(EOF) or on a new line, whichever comes first. The file to be read and the number of bytes 2 min read PHP | fgetc( ) Function The fgetc() function in PHP is an inbuilt function which is used to return a single character from an open file. It is used to get a character from a given file pointer. The file to be checked is used as a parameter to the fgetc() function and it returns a string containing a single character from t 2 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 ftruncate( ) Function The ftruncate() function in PHP is an inbuilt function that is used to truncate(shorten) an open file to the specified length. The file and the new size of the file are sent as parameters to the ftruncate() function and it returns True on success and False on Failure. If the size specified in the pa 2 min read PHP | ftell( ) Function The ftell() function in PHP is an inbuilt function which is used to return the current position in an open file. The file is sent as a parameter to the ftell() function and it returns the current file pointer position on success, or FALSE on failure.Syntax:Â Â ftell( $file ) Parameters Used: The ftel 2 min read PHP | fseek( ) Function The fseek() function in PHP is an inbuilt function which is used to seek in an open file. It moves the file pointer from its current position to a new position, forward or backward specified by the number of bytes. The file and the offset are sent as parameters to the fseek() function and it returns 2 min read PHP fclose() Function The fclose() function in PHP closes a file that was previously opened by fopen(). Closing a file releases the resource associated with it and makes sure all the data written to the file is properly saved. Not closing files can lead to resource leaks or incomplete data writing.Syntax:bool fclose(reso 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 PHP | fileatime( ) Function The fileatime() function in PHP is an inbuilt function which is used to return the last access time of a specified file. The fileatime() function returns the last access time of a file as a Unix Timestamp on success and False on failure. The filename is passed as a parameter to the fileatime() funct 2 min read Like