Easy Tutorial
❮ Func Simplexml Registerxpathnamespace Func Math Bindec ❯

PHP flock() Function



Definition and Usage

The flock() function locks or releases a file.

If successful, the function returns TRUE. If it fails, it returns FALSE.

Syntax

Parameter Description
file Required. Specifies the open file to lock or release.
lock Required. Specifies the type of lock to use. Possible values: LOCK_SH - Shared lock (for reading). Allows other processes to access the file. <br> LOCK_EX - Exclusive lock (for writing). Prevents other processes from accessing the file. <br> LOCK_UN - Releases a shared or exclusive lock. <br> LOCK_NB - Avoids blocking other processes during locking.
block Optional. If set to 1, blocks other processes during the locking operation.

Tips and Notes

Note: These locks are only used within the current PHP process. If permissions allow, other processes can modify or delete a PHP-locked file.

Note: flock() is mandatory under Windows.

Tip: You can release the lock operation with fclose(), which is automatically called when the script finishes execution.


Examples


❮ Func Simplexml Registerxpathnamespace Func Math Bindec ❯