PHP4 User Manual: function-flock

Source: Internet
Author: User
Tags flock

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.