class SyncReaderWriter (View source)

SyncReaderWriter

A cross-platform, native implementation of named and unnamed reader-writer objects. A reader-writer object allows many readers or one writer to access a resource. This is an efficient solution for managing resources where access will primarily be read-only but exclusive write access is occasionally necessary.

Methods

__construct(string $name, bool $autounlock = true)

Constructs a new SyncReaderWriter object

bool
readlock(int $wait = -1)

Waits for a read lock

bool
readunlock()

Releases a read lock

bool
writelock(int $wait = -1)

Waits for an exclusive write lock

bool
writeunlock()

Releases a write lock

Details

__construct(string $name, bool $autounlock = true)

Constructs a new SyncReaderWriter object

Constructs a named or unnamed reader-writer object.

Parameters

string $name

[optional] The name of the reader-writer if this is a named reader-writer object. Note: If the name already exists, it must be able to be opened by the current user that the process is running as or an exception will be thrown with a meaningless error message.

bool $autounlock

[optional] Specifies whether or not to automatically unlock the reader-writer at the conclusion of the PHP script. Warning: If an object is: A named reader-writer with an autounlock of FALSE, the object is locked for either reading or writing, and the PHP script concludes before the object is unlocked, then the underlying objects will end up in an inconsistent state.

Exceptions

Exception

bool readlock(int $wait = -1)

Waits for a read lock

Obtains a read lock on a SyncReaderWriter object.

Parameters

int $wait

[optional] The number of milliseconds to wait for a lock. A value of -1 is infinite.

Return Value

bool

TRUE if the lock was obtained, FALSE otherwise.

See also

SyncReaderWriter::readunlock

bool readunlock()

Releases a read lock

Releases a read lock on a SyncReaderWriter object.

Return Value

bool

TRUE if the unlock operation was successful, FALSE otherwise.

See also

SyncReaderWriter::readlock

bool writelock(int $wait = -1)

Waits for an exclusive write lock

Obtains an exclusive write lock on a SyncReaderWriter object.

Parameters

int $wait

[optional] The number of milliseconds to wait for a lock. A value of -1 is infinite.

Return Value

bool

TRUE if the lock was obtained, FALSE otherwise.

See also

SyncReaderWriter::writeunlock

bool writeunlock()

Releases a write lock

Releases a write lock on a SyncReaderWriter object.

Return Value

bool

TRUE if the unlock operation was successful, FALSE otherwise.

See also

SyncReaderWriter::writelock