class flock

File locking class

Methods

__construct(string $path)

Constructor.

bool
acquire()

Tries to acquire the lock.

bool
owns_lock()

Does this process own the lock?

null
release()

Releases the lock.

Details

at line 41
__construct(string $path)

Constructor.

You have to call acquire() to actually acquire the lock.

Parameters

string $path

Path to the file to which access is controlled

at line 65
bool acquire()

Tries to acquire the lock.

If the lock is already held by another process, this call will block until the other process releases the lock. If a lock is acquired and is not released before script finishes but the process continues to live (apache/fastcgi) then subsequent processes trying to acquire the same lock will be blocked forever.

If the lock is already held by the same process via another instance of this class, this call will block forever.

If flock function is disabled in php or fails to work, lock acquisition will fail and false will be returned.

Return Value

bool

true if lock was acquired false otherwise

at line 119
bool owns_lock()

Does this process own the lock?

Return Value

bool

true if lock is owned false otherwise

at line 135
null release()

Releases the lock.

The lock must have been previously obtained, that is, acquire() call was issued and returned true.

Note: Attempting to release a lock that is already released, that is, calling release() multiple times, is harmless.

Return Value

null