fclose

bool fclose(resource file_handle) 

Closes a file.

Returns:

TRUE on success; FALSE on error

Description:

Closes a file opened by fopen() or fsockopen(). Closing a file handle ensures that any buffered data is written to the file. This behavior can be the cause of relatively subtle bugs when working with files.

Warning:

3.0.6, 3.0.11: Doesn’t seem to close TCP sockets on Linux, already reported with 3.0.6.

3.0.7: May cause PHP to crash on Red Hat Linux 5.2.

Example:

Open and close a file
$fh = fopen ("test.txt", "r"); 
fclose ($fh); 

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.