flock
Lightweight consultation file locking
flock()
function locks or releases a file.
If successful, return true. If it fails, return false.
<?php $file = fopen ( "test.txt" , "w+" ) ; // Exclusive locking if ( flock ( $file , LOCK_EX ) ) { fwrite ( $file , "Write something" ) ; // release lock flock ( $file , LOCK_UN ) ; } else { echo "Error locking file!" ; } fclose ( $file ) ; ?>
flock ( file , lock , block )
parameter | describe |
---|---|
file | Required. Specifies the opened file to be locked or released. |
lock | Required. Specify which lock type to be used. |
Block | Optional. If set to 1 or true, block other processes when locking is performed. |
The file for the flock() operation must be an open file pointer.
The lock parameter can be one of the following values: