Home > Backend Development > PHP Tutorial > PHP4 User Manual: Function-flock_PHP Tutorial

PHP4 User Manual: Function-flock_PHP Tutorial

WBOY
Release: 2016-07-13 17:22:22
Original
1186 people have browsed it

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() ).


Warning
flock() will not work on NFS and other network file systems. Consult your operating system documentation for details.
Some operating systems require flock() to execute at a certain execution level. When using multi-threaded system APIs like ISAPI, you cannot rely on flock() to protect files while other PHP scripts are running in parallel threads on the same server instance.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532341.htmlTechArticleflock (PHP 3>= 3.0.7, PHP 4 >= 4.0.0)flock -- lock file description bool flock (int fp, int operation [, int wouldblock]) PHP supports complete locking of files when accessing them (this means that all...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template