WorkerGroup

Class
Final: Yes

Provides an immutable view over a collection of workers created by the same manager.

Description

This class acts as a value object representing a group of workers and offers convenience methods for querying and interacting with them collectively.

Instances of this class MUST be treated as immutable. Consumers SHOULD NOT attempt to modify the internal worker collection after instantiation.

Table of Contents

Interfaces

WorkerGroupInterface

Defines an immutable group of workers.

Properties

$workers

Stores the workers tracked by this group.

 : array<int, WorkerInterface>

Methods

__construct()

Initializes the worker group.

 : mixed
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
Properties
Methods

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
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>
Return values
Traversable<int, WorkerInterface>

Description

iterator over workers

wait()

Public

Waits until all workers in this group have finished.

public wait() : void