Reactor
+ Inheritance diagram for Reactor:

Description

Selects and calls reactive sockets when they are readable.

Protected Properties

ReactiveInterface[] $sockets = []
 All sockets in the reactor, keyed by ID. More...
 

Public Static Methods

static int select (array &$read, array &$write, array &$except, ?float $timeout=null)
 Selects instances. More...
 

Public Methods

$this add (ReactiveInterface $socket)
 Adds a reactive socket for selection. More...
 
int count ()
 The number of reactive sockets in the reactor. More...
 
ReactiveInterface[] getSockets ()
 
bool has (ReactiveInterface $socket)
 Whether a socket is in the reactor. More...
 
int react (?float $timeout=null)
 Selects the reactor's sockets and calls their reactive methods. More...
 
$this remove (ReactiveInterface $socket)
 Removes a socket from the reactor. More...
 

Protected Methods

void onError (int $channel, $socket, Throwable $error)
 

Properties

◆ $sockets

ReactiveInterface [] $sockets = []
protected

All sockets in the reactor, keyed by ID.

Methods

◆ add()

$this add ( ReactiveInterface  $socket)

Adds a reactive socket for selection.

Parameters
ReactiveInterface$socket
Returns
$this

◆ count()

int count ( )

The number of reactive sockets in the reactor.

Returns
int

◆ getSockets()

ReactiveInterface [] getSockets ( )

◆ has()

bool has ( ReactiveInterface  $socket)

Whether a socket is in the reactor.

Parameters
ReactiveInterface$socket
Returns
bool

◆ onError()

void onError ( int  $channel,
  $socket,
Throwable  $error 
)
protected
Parameters
int$channel
ReactiveInterface$socket
Throwable$error

◆ react()

int react ( ?float  $timeout = null)

Selects the reactor's sockets and calls their reactive methods.

Invoke this in a loop that checks Reactor::count() a condition.

Closed sockets are automatically removed from the reactor.

Parameters
float | null$timeoutMaximum seconds to block. NULL blocks forever.
Returns
int Number of sockets selected.

◆ remove()

$this remove ( ReactiveInterface  $socket)

Removes a socket from the reactor.

Parameters
ReactiveInterface$socket
Returns
$this

◆ select()

static int select ( array &  $read,
array &  $write,
array &  $except,
?float  $timeout = null 
)
static

Selects instances.

Can be used to select non-reactive sockets.

See also
https://php.net/socket_select
Parameters
SocketInterface[]$read
SocketInterface[]$write
SocketInterface[]$except
float | null$timeoutMaximum seconds to block. NULL blocks forever.
Returns
int
Exceptions
SocketError