Flock (PHP33.0.7, PHP44.0.0) flock -- lock the file description boolflock (intfp, memory peration [, intwouldblock]) PHP supports full file locking when accessing files (this means that all access programs have to use the same locking method, or it does not work ). FSynt
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 full file locking when accessing files (this means that all access programs have to use the same locking method, or it does not work ).
Flock () runs on the opened file pointer fp.
Operation is one of the following values:
Obtain a shared Lock (readable) and set it to LOCK_SH (1 below PHP 4.0.1 );
Obtain a mutex lock (only writable) and set it to LOCK_EX (set to 2 below PHP 4.0.1 );
Release the lock (release the shared lock or mutex lock) and set it to LOCK_UN (set it to 3 below PHP 4.0.1 );
If you do not want flock () blocks when locking, add LOCK_NB (set to 4 below PHP 4.0.1 ).
Flock () allows you to use simple read/write modes on every platform (including many Unix-derived systems and Windows systems ). if you want to lock the block, you can set the third parameter to TRUE (EWOULDBLOCK errno condition)
Flock () returns TRUE to succeed; returns FALSE to fail (e.g. when a lock cocould 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 \ phpphp user manual fancyfunction.fopen.html> fopen ()).
Warning
Flock () will not work in NFS and other network file systems. For more information, see your operating system file.
Some operating systems need to execute flock () at a certain level. When using multi-threaded system APIs like isapis, you cannot rely on flock () to protect files. On the contrary, other PHP scripts are running in parallel lines on the same server instance.