PHP4 User manual: Function-flock_php Tutorial

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 locking of files when accessing files (which means that all access programs have to use the same locking method, or that it does not work).
Flock () runs above the open file pointer fp.
Operation is one of the following values:
Get a shared lock (readable), set to Lock_sh (PHP 4.0.1 below is set to 1);
Get a mutex (only self-writable), set to LOCK_EX (PHP 4.0.1 below is set to 2);
Release the lock (release the shared or mutex), set to Lock_un (PHP 4.0.1 below is set to 3);
If you do not want to flock () block when locked, add LOCK_NB (PHP 4.0.1 below is set to 4).
Flock () allows you to use simple read/write modes (including numerous Unix derived systems and Windows systems) on every platform. If you want to lock a block, you can set the third argument 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 can have the use of a special lock file to the protect access to a file, the intend to the truncate by Opening it in write mode (with a "w" or "w+" argument to Web site Building Server script Class \phpphp user manual Fancyfunction.fopen.html>fopen ()).

Warning
Flock () will not work in NFS and other network file systems. Please refer to your operating system files for more information.
Some operating systems flock () require execution at a certain level of execution. When using the multithreaded system API like ISAPI, you can not rely on flock () to protect files, whereas other PHP scripts are running in parallel threads in the same instance of the server.

http://www.bkjia.com/PHPjc/532341.html www.bkjia.com true http://www.bkjia.com/PHPjc/532341.html techarticle Flock (php 3>= 3.0.7, PHP 4 >= 4.0.0) Flock--Lock file description bool Flock (int fp, int operation [, int wouldblock]) PHP Branch Lock the file when accessing the file (which means ...

  • Related Article

    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.