ForkManagerInterface

Interface

Implementations of this interface MUST provide the orchestration layer responsible for spawning, supervising, signaling, and synchronizing worker processes.

Description

Implementations SHOULD ensure predictable lifecycle management and MUST expose enough behavior to distinguish master and worker execution contexts.

The key words "MUST", "MUST NOT", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this contract are to be interpreted as described in RFC 2119.

Table of Contents

Methods

fork()

Forks one or more workers for the provided callback and returns them as a group.

 : WorkerGroupInterface
getMasterPid()

Returns the PID of the master process associated with this manager.

 : int
isMaster()

Indicates whether the current execution context is the master process.

 : bool
isSupported()

Indicates whether the current runtime supports the library requirements.

 : bool
isWorker()

Indicates whether the current execution context is a worker process.

 : bool
kill()

Sends a signal to all targeted workers.

 : void
wait()

Waits until all targeted workers finish.

 : void
Methods

fork()

Public

Forks one or more workers for the provided callback and returns them as a group.

public fork( callable(WorkerInterface): mixed  $workerCallback[, int  $workerCount = 1]) : WorkerGroupInterface

Description

The callback MUST receive the current worker as its first argument. Implementations MUST create exactly the requested number of workers when the operation succeeds. If the runtime cannot complete the operation safely, implementations SHOULD fail explicitly rather than returning a partial and misleading result.

Parameters
$workerCallback : callable(WorkerInterface): mixed

Description

callback executed inside each worker process

$workerCount : int = 1

Description

number of workers to create for the callback

Return values

Description

a group representing the workers created for the provided callback

getMasterPid()

Public

Returns the PID of the master process associated with this manager.

public getMasterPid() : int

Description

The returned process identifier MUST correspond to the process recognized by the implementation as the master orchestration context.

Return values
int

Description

the process identifier of the master process

isMaster()

Public

Indicates whether the current execution context is the master process.

public isMaster() : bool

Description

Implementations MUST return true only when the current process matches the master process associated with the manager instance.

Return values
bool

Description

true when the current process is the master process; otherwise, false

isSupported()

Public

Indicates whether the current runtime supports the library requirements.

public isSupported() : bool

Description

Implementations MUST validate the availability of the runtime capabilities required to manage worker processes correctly. The returned value SHALL reflect whether the execution environment is suitable for safe operation.

Return values
bool

Description

true when the runtime environment supports the required process control features; otherwise, false

isWorker()

Public

Indicates whether the current execution context is a worker process.

public isWorker() : bool

Description

Implementations SHOULD treat this result as the logical inverse of the master-process check whenever that model is valid for the implementation.

Return values
bool

Description

true when the current process is executing as a worker; otherwise, false

kill()

Public

Sends a signal to all targeted workers.

public kill([Signal  $signal = Signal::Terminate], WorkerInterface|WorkerGroupInterface  ...$workers) : void

Description

When no worker or group is provided, implementations MUST signal every worker instantiated by this manager. Implementations SHOULD ensure that the signal is delivered only to workers under their own control and MUST NOT silently target unrelated processes.

Parameters

Description

signal to send to each targeted worker

Description

Workers and groups to signal.

wait()

Public

Waits until all targeted workers finish.

public wait(WorkerInterface|WorkerGroupInterface  ...$workers) : void

Description

When no worker or group is provided, implementations MUST wait for every worker instantiated by this manager. Implementations SHALL block until the targeted workers have exited or have otherwise been fully reconciled by the manager lifecycle.

Parameters

Description

Workers and groups to wait for.