PHP4 User Manual: Function -> FLOCK

zhaozj2021-02-08  259

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 a fully locked file when accessing the file (this means that all access programs have to use the same lock mode, or it does not work).

FLOCK () is running on 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 is set below); get a mutex (written only if you can write), set to Lock_ex (PHP 4.0.1 set to 2); release Lock (release shared lock or mutex), set to Lock_un (PHP 4.0.1 is set to 3); if you don't want a flock () block when locking, add Lock_nb (set to 4 below PHP 4.0.1).

FLOCK () allows you to be able to use simple read / write mode on each platform (including numerous 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; returning false is a failure (E.G. When a Lock Could Not Be acquired).

Note: Because FLOCK () requires a file pointer, you May Have to use one a special lock file to protect access to a file try in Write Mode (with a "w" or "w " argument to fopen ()).

WARNING FLOCK () will not work in NFS and other network file systems. For details, please check your operating system files. Some operating systems FLOCK () execution requires at a certain level of execution. When using multi-threaded system API icons ISAPI, you cannot rely on flock () to protect files, and other PHP scripts are running in parallel in the same server instance.

转载请注明原文地址:https://www.9cbs.com/read-3435.html

New Post(0)