Documentation

PosixSemaphore
in package
implements Semaphore uses ForbidCloning, ForbidSerialization

FinalYes

A non-blocking, inter-process POSIX semaphore.

Uses a POSIX message queue to store a queue of permits in a lock-free data structure. This semaphore implementation is preferred over other implementations when available, as it provides the best performance.

Not compatible with Windows.

Table of Contents

Interfaces

Semaphore
A counting semaphore.

Constants

LATENCY_TIMEOUT  = 0.01
MAX_ID  = 0x7fffffff

Properties

$errorHandler  : Closure
$initializer  : int
$key  : int
$nextId  : int
$queue  : SysvMessageQueue

Methods

__destruct()  : mixed
Removes the semaphore if it still exists.
__serialize()  : never
__unserialize()  : never
acquire()  : Lock
Acquires a lock on the semaphore. Semaphores may have one or more locks.
create()  : self
Creates a new semaphore with a given ID and number of locks.
getKey()  : int
getPermissions()  : int
Gets the access permissions of the semaphore.
setPermissions()  : void
Sets the access permissions of the semaphore.
use()  : self
__clone()  : mixed
__construct()  : mixed
getNextId()  : int
release()  : void
Releases a lock from the semaphore.

Constants

Properties

Methods

__destruct()

Removes the semaphore if it still exists.

public __destruct() : mixed
Tags
throws
SyncException

If the operation failed.

__unserialize()

public final __unserialize(array<string|int, mixed> $data) : never
Parameters
$data : array<string|int, mixed>
Return values
never

acquire()

Acquires a lock on the semaphore. Semaphores may have one or more locks.

public acquire() : Lock
Return values
Lock

Returns with a lock object once a lock is obtained. May fail with a SyncException if an error occurs when attempting to obtain the lock (e.g. a shared memory segment closed).

create()

Creates a new semaphore with a given ID and number of locks.

public static create(int $maxLocks[, int $permissions = 0600 ]) : self
Parameters
$maxLocks : int

The maximum number of locks that can be acquired from the semaphore.

$permissions : int = 0600

Permissions to access the semaphore. Use file permission format specified as 0xxx.

Tags
throws
SyncException

If the semaphore could not be created due to an internal error.

Return values
self

getPermissions()

Gets the access permissions of the semaphore.

public getPermissions() : int
Return values
int

A permissions mode.

setPermissions()

Sets the access permissions of the semaphore.

public setPermissions(int $mode) : void

The current user must have access to the semaphore in order to change the permissions.

Parameters
$mode : int

A permissions mode to set.

Tags
throws
SyncException

If the operation failed.

use()

public static use(int $key) : self
Parameters
$key : int

Use getKey() on the creating process and send this key to another process.

Return values
self

__construct()

private __construct(SysvMessageQueue $queue, int $key, int $initializer) : mixed
Parameters
$queue : SysvMessageQueue
$key : int
$initializer : int

PID of the process that created the semaphore or 0 if the semaphore was only opened in this process.

Tags
throws
Error

If the sysvmsg extension is not loaded.


        
On this page

Search results