Home >Backend Development >PHP Tutorial >PHP4 User Manual: Function-flock_PHP Tutorial
flock
(PHP 3>= 3.0.7, PHP 4 >= 4.0.0)flock -- lock file description
bool flock (int fp, int operation [, int wouldblock])
PHP supports in Completely lock the file when accessing it (this means that all accessing programs have to use the same locking method, or it doesn't work).
flock() operates on the open file pointer fp.
operation is one of the following values:
Obtain a shared lock (readable), set to LOCK_SH (set to 1 below PHP 4.0.1);
Obtain a mutex lock (only writable by yourself) , set to LOCK_EX (set to 2 below PHP 4.0.1);
Release the lock (release a shared lock or mutex lock), set to LOCK_UN (set to 3 below PHP 4.0.1);
If when locked When you don't want flock() blocks, add LOCK_NB (set to 4 below PHP 4.0.1).
flock() allows you to use simple read/write mode on every platform (including many Unix derivatives and Windows systems). If you want to lock the block, you can set the third parameter to TRUE (EWOULDBLOCK errno condition)
flock() returns TRUE for success; returns FALSE for failure (e.g. when a lock could not be acquired).
Note: Because flock() requires a file pointer, you may have to use a special lock file to protect access to a file that you intend to truncate by opening it in write mode (with a "w" or "w+" argument to Website Construction Server Script Class PHPPHP User Manual fancyfunction.fopen.html>fopen() ).