ExtUvLoop
in package
implements
LoopInterface
An `ext-uv` based event loop.
This loop uses the uv
PECL extension,
that provides an interface to libuv
library.
libuv
itself supports a number of system-specific backends (epoll, kqueue).
This loop is known to work with PHP 7+.
Tags
Table of Contents
Interfaces
Properties
- $futureTickQueue : mixed
- $readStreams : mixed
- $running : mixed
- $signalEvents : mixed
- $signals : mixed
- $streamEvents : mixed
- $streamListener : mixed
- $timers : mixed
- $uv : mixed
- $writeStreams : mixed
Methods
- __construct() : mixed
- addPeriodicTimer() : TimerInterface
- Enqueue a callback to be invoked repeatedly after the given interval.
- addReadStream() : mixed
- [Advanced] Register a listener to be notified when a stream is ready to read.
- addSignal() : void
- Register a listener to be notified when a signal has been caught by this process.
- addTimer() : TimerInterface
- Enqueue a callback to be invoked once after the given interval.
- addWriteStream() : mixed
- [Advanced] Register a listener to be notified when a stream is ready to write.
- cancelTimer() : void
- Cancel a pending timer.
- futureTick() : void
- Schedule a callback to be invoked on a future tick of the event loop.
- removeReadStream() : mixed
- Remove the read event listener for the given stream.
- removeSignal() : void
- Removes a previously added signal listener.
- removeWriteStream() : mixed
- Remove the write event listener for the given stream.
- run() : void
- Run the event loop until there are no more tasks to perform.
- stop() : void
- Instruct a running event loop to stop.
- addStream() : mixed
- convertFloatSecondsToMilliseconds() : int
- createStreamListener() : callable
- Create a stream listener
- pollStream() : mixed
- removeStream() : mixed
Properties
$futureTickQueue
private
mixed
$futureTickQueue
$readStreams
private
mixed
$readStreams
= array()
$running
private
mixed
$running
$signalEvents
private
mixed
$signalEvents
= array()
$signals
private
mixed
$signals
$streamEvents
private
mixed
$streamEvents
= array()
$streamListener
private
mixed
$streamListener
$timers
private
mixed
$timers
$uv
private
mixed
$uv
$writeStreams
private
mixed
$writeStreams
= array()
Methods
__construct()
public
__construct() : mixed
addPeriodicTimer()
Enqueue a callback to be invoked repeatedly after the given interval.
public
addPeriodicTimer(mixed $interval, mixed $callback) : TimerInterface
Parameters
- $interval : mixed
-
The number of seconds to wait before execution.
- $callback : mixed
-
The callback to invoke.
Return values
TimerInterfaceaddReadStream()
[Advanced] Register a listener to be notified when a stream is ready to read.
public
addReadStream(mixed $stream, mixed $listener) : mixed
Parameters
- $stream : mixed
-
The PHP stream resource to check.
- $listener : mixed
-
Invoked when the stream is ready.
addSignal()
Register a listener to be notified when a signal has been caught by this process.
public
addSignal(mixed $signal, mixed $listener) : void
This is useful to catch user interrupt signals or shutdown signals from
tools like supervisor
or systemd
.
The second parameter MUST be a listener callback function that accepts the signal as its only parameter. If you don't use the signal inside your listener callback function you MAY use a function which has no parameters at all.
The listener callback function MUST NOT throw an Exception
.
The return value of the listener callback function will be ignored and has
no effect, so for performance reasons you're recommended to not return
any excessive data structures.
$loop->addSignal(SIGINT, function (int $signal) {
echo 'Caught user interrupt signal' . PHP_EOL;
});
See also example #4.
Signaling is only available on Unix-like platforms, Windows isn't
supported due to operating system limitations.
This method may throw a BadMethodCallException
if signals aren't
supported on this platform, for example when required extensions are
missing.
Note: A listener can only be added once to the same signal, any attempts to add it more than once will be ignored.
Parameters
- $signal : mixed
- $listener : mixed
addTimer()
Enqueue a callback to be invoked once after the given interval.
public
addTimer(mixed $interval, mixed $callback) : TimerInterface
Parameters
- $interval : mixed
-
The number of seconds to wait before execution.
- $callback : mixed
-
The callback to invoke.
Return values
TimerInterfaceaddWriteStream()
[Advanced] Register a listener to be notified when a stream is ready to write.
public
addWriteStream(mixed $stream, mixed $listener) : mixed
Parameters
- $stream : mixed
-
The PHP stream resource to check.
- $listener : mixed
-
Invoked when the stream is ready.
cancelTimer()
Cancel a pending timer.
public
cancelTimer(TimerInterface $timer) : void
Parameters
- $timer : TimerInterface
-
The timer to cancel.
futureTick()
Schedule a callback to be invoked on a future tick of the event loop.
public
futureTick(mixed $listener) : void
Parameters
- $listener : mixed
-
The callback to invoke.
removeReadStream()
Remove the read event listener for the given stream.
public
removeReadStream(mixed $stream) : mixed
Parameters
- $stream : mixed
-
The PHP stream resource.
removeSignal()
Removes a previously added signal listener.
public
removeSignal(mixed $signal, mixed $listener) : void
$loop->removeSignal(SIGINT, $listener);
Any attempts to remove listeners that aren't registered will be ignored.
Parameters
- $signal : mixed
- $listener : mixed
removeWriteStream()
Remove the write event listener for the given stream.
public
removeWriteStream(mixed $stream) : mixed
Parameters
- $stream : mixed
-
The PHP stream resource.
run()
Run the event loop until there are no more tasks to perform.
public
run() : void
stop()
Instruct a running event loop to stop.
public
stop() : void
addStream()
private
addStream(mixed $stream) : mixed
Parameters
- $stream : mixed
convertFloatSecondsToMilliseconds()
private
convertFloatSecondsToMilliseconds(float $interval) : int
Parameters
- $interval : float
Return values
intcreateStreamListener()
Create a stream listener
private
createStreamListener() : callable
Return values
callable —Returns a callback
pollStream()
private
pollStream(mixed $stream) : mixed
Parameters
- $stream : mixed
removeStream()
private
removeStream(mixed $stream) : mixed
Parameters
- $stream : mixed