WorkerGroupInterface

Interface
extends Countable IteratorAggregate

Defines an immutable group of workers.

Description

Implementations MUST represent a read-only collection of workers that were created by the same manager instance. The group SHALL provide consistent access, iteration, and batch operations over the underlying workers.

Consumers MAY use this abstraction to coordinate multiple workers as a single unit without managing them individually.

Tags
extends

Table of Contents

Methods

all()

Returns all tracked workers.

 : array<int, WorkerInterface>
count()

Returns the number of tracked workers.

 : int
get()

Returns a worker by its PID.

 : WorkerInterface|null
getIterator()

Returns an iterator for the tracked workers.

 : Traversable<int, WorkerInterface>
getManager()

Returns the manager that created this worker group.

 : ForkManagerInterface
getRunning()

Returns the workers that are currently running.

 : array<int, WorkerInterface>
getStopped()

Returns the workers that are no longer running.

 : array<int, WorkerInterface>
kill()

Sends a signal to all workers in this group.

 : void
wait()

Waits until all workers in this group have finished.

 : void
Methods

all()

Public

Returns all tracked workers.

public all() : array<int, WorkerInterface>

Description

The returned array MUST contain all workers belonging to this group and SHALL be indexed by their process identifiers (PID).

Return values
array<int, WorkerInterface>

Description

all workers in the group

count()

Public

Returns the number of tracked workers.

public count() : int
Return values
int

Description

total number of workers in the group

get()

Public

Returns a worker by its PID.

public get( int  $pid) : WorkerInterface|null

Description

If no worker exists for the given PID, the method MUST return null.

Parameters
$pid : int

Description

the process identifier of the worker

Return values

Description

the matching worker or null if not found

getIterator()

Public

Returns an iterator for the tracked workers.

public getIterator() : Traversable<int, WorkerInterface>

Description

The iterator MUST provide read-only traversal over the worker collection.

Return values
Traversable<int, WorkerInterface>

Description

iterator over workers

getManager()

Public

Returns the manager that created this worker group.

public getManager() : ForkManagerInterface

Description

The returned manager MUST be the same instance responsible for all workers contained in this group.

Return values

Description

the manager associated with this group

getRunning()

Public

Returns the workers that are currently running.

public getRunning() : array<int, WorkerInterface>

Description

Implementations MUST return only workers whose execution has not yet completed.

Return values
array<int, WorkerInterface>

Description

running workers

getStopped()

Public

Returns the workers that are no longer running.

public getStopped() : array<int, WorkerInterface>

Description

Implementations MUST return only workers that have already terminated or are no longer active.

Return values
array<int, WorkerInterface>

Description

stopped workers

kill()

Public

Sends a signal to all workers in this group.

public kill([Signal  $signal = Signal::Terminate]) : void

Description

Implementations MUST ensure that the signal is delivered only to workers belonging to this group.

Parameters

Description

the signal to send to each worker

wait()

Public

Waits until all workers in this group have finished.

public wait() : void

Description

Implementations MUST block until all workers have terminated or have been fully reconciled by the manager.