final class EvLoop (View source)

Class EvLoop

Represents an event loop that is always distinct from the default loop. Unlike the default loop, it cannot handle EvChild watchers.

Having threads we have to create a loop per thread, and use the the default loop in the parent thread.

The default event loop is initialized automatically by Ev. It is accessible via methods of the Ev class, or via EvLoop::defaultLoop() method.

Properties

int $backend
bool $is_default_loop
mixed $data
int $iteration
int $pending
float $io_interval
float $timeout_interval
int $depth

Methods

__construct(int $flags = Ev::FLAG_AUTO, mixed $data = null, float $io_interval = 0.0, float $timeout_interval = 0.0)

No description

int
backend()

Returns an integer describing the backend used by libev.

check(callable $callback, mixed $data = null, int $priority = 0)

Creates EvCheck object associated with the current event loop instance.

child(int $pid, bool $trace, mixed $callback, mixed $data = null, int $priority = 0)

Creates EvChild object associated with the current event loop instance;

embed(EvLoop $other, callable $callback, mixed $data = null, int $priority = 0)

Creates EvEmbed object associated with the current event loop instance.

fork(callable $callback, mixed $data = null, int $priority = 0)

Creates EvFork object associated with the current event loop instance.

idle(mixed $callback, mixed $data = null, int $priority = 0)

Creates EvIdle object associated with the current event loop instance.

invokePending()

Invoke all pending watchers while resetting their pending state.

io(mixed $fd, int $events, mixed $callback, mixed $data = null, int $priority = 0)

Creates EvIo object associated with the current event loop instance.

loopFork()

Must be called after a fork.

float
now()

Returns the current "event loop time".

nowUpdate()

Establishes the current time by querying the kernel, updating the time returned by Ev::now in the progress.

periodic(float $offset, float $interval, mixed $reschedule_cb, mixed $callback, mixed $data = null, int $priority = 0)

Creates EvPeriodic object associated with the current event loop instance.

prepare(callable $callback, mixed $data = null, int $priority = 0)

Creates EvPrepare object associated with the current event loop instance.

resume()

Resume previously suspended default event loop.

run(int $flags = Ev::FLAG_AUTO)

Begin checking for events and calling callbacks for the loop.

signal(int $signum, mixed $callback, mixed $data = null, int $priority = 0)

Creates EvSignal object associated with the current event loop instance.

stat(string $path, float $interval, mixed $callback, mixed $data = null, int $priority = 0)

Creates EvStats object associated with the current event loop instance.

stop(int $how = Ev::BREAK_ALL)

Stops the event loop.

suspend()

Suspend the loop.

timer(float $after, float $repeat, mixed $callback, mixed $data = null, int $priority = 0)

Creates EvTimer object associated with the current event loop instance.

verify()

Performs internal consistency checks (for debugging).

static EvLoop
defaultLoop(int $flags = Ev::FLAG_AUTO, mixed $data = null, float $io_interval = 0.0, float $timeout_interval = 0.0)

Returns or creates the default event loop.

Details

__construct(int $flags = Ev::FLAG_AUTO, mixed $data = null, float $io_interval = 0.0, float $timeout_interval = 0.0)

No description

Parameters

int $flags
mixed $data
float $io_interval
float $timeout_interval

int backend()

Returns an integer describing the backend used by libev.

Return Value

int

An integer describing the backend used by libev. See Ev::backend().

final EvCheck check(callable $callback, mixed $data = null, int $priority = 0)

Creates EvCheck object associated with the current event loop instance.

Parameters

callable $callback
mixed $data
int $priority

Return Value

EvCheck

final EvChild child(int $pid, bool $trace, mixed $callback, mixed $data = null, int $priority = 0)

Creates EvChild object associated with the current event loop instance;

Parameters

int $pid
bool $trace
mixed $callback
mixed $data
int $priority

Return Value

EvChild

final EvEmbed embed(EvLoop $other, callable $callback, mixed $data = null, int $priority = 0)

Creates EvEmbed object associated with the current event loop instance.

Parameters

EvLoop $other
callable $callback
mixed $data
int $priority

Return Value

EvEmbed

final EvFork fork(callable $callback, mixed $data = null, int $priority = 0)

Creates EvFork object associated with the current event loop instance.

Parameters

callable $callback
mixed $data
int $priority

Return Value

EvFork

final EvIdle idle(mixed $callback, mixed $data = null, int $priority = 0)

Creates EvIdle object associated with the current event loop instance.

Parameters

mixed $callback
mixed $data
int $priority

Return Value

EvIdle

invokePending()

Invoke all pending watchers while resetting their pending state.

final EvIo io(mixed $fd, int $events, mixed $callback, mixed $data = null, int $priority = 0)

Creates EvIo object associated with the current event loop instance.

Parameters

mixed $fd
int $events
mixed $callback
mixed $data
int $priority

Return Value

EvIo

loopFork()

Must be called after a fork.

Must be called after a fork in the child, before entering or continuing the event loop. An alternative is to use Ev::FLAG_FORKCHECK which calls this function automatically, at some performance loss (refer to the libev documentation).

float now()

Returns the current "event loop time".

Returns the current "event loop time", which is the time the event loop received events and started processing them. This timestamp does not change as long as callbacks are being processed, and this is also the base time used for relative timers. You can treat it as the timestamp of the event occurring (or more correctly, libev finding out about it).

Return Value

float

Time of the event loop in (fractional) seconds.

nowUpdate()

Establishes the current time by querying the kernel, updating the time returned by Ev::now in the progress.

Establishes the current time by querying the kernel, updating the time returned by Ev::now() in the progress. This is a costly operation and is usually done automatically within Ev::run().

This method is rarely useful, but when some event callback runs for a very long time without entering the event loop, updating libev's consideration of the current time is a good idea.

final periodic(float $offset, float $interval, mixed $reschedule_cb, mixed $callback, mixed $data = null, int $priority = 0)

Creates EvPeriodic object associated with the current event loop instance.

Parameters

float $offset
float $interval
mixed $reschedule_cb
mixed $callback
mixed $data
int $priority

final prepare(callable $callback, mixed $data = null, int $priority = 0)

Creates EvPrepare object associated with the current event loop instance.

Parameters

callable $callback
mixed $data
int $priority

resume()

Resume previously suspended default event loop.

EvLoop::suspend() and EvLoop::resume() methods suspend and resume a loop correspondingly.

run(int $flags = Ev::FLAG_AUTO)

Begin checking for events and calling callbacks for the loop.

Begin checking for events and calling callbacks for the current event loop. Returns when a callback calls Ev::stop() method, or the flags are nonzero (in which case the return value is true) or when there are no active watchers which reference the loop (EvWatcher::keepalive() is TRUE), in which case the return value will be FALSE. The return value can generally be interpreted as if TRUE, there is more work left to do.

Parameters

int $flags

One of the Ev::RUN_* flags.

final EvSignal signal(int $signum, mixed $callback, mixed $data = null, int $priority = 0)

Creates EvSignal object associated with the current event loop instance.

Parameters

int $signum
mixed $callback
mixed $data
int $priority

Return Value

EvSignal

final EvStat stat(string $path, float $interval, mixed $callback, mixed $data = null, int $priority = 0)

Creates EvStats object associated with the current event loop instance.

Parameters

string $path
float $interval
mixed $callback
mixed $data
int $priority

Return Value

EvStat

stop(int $how = Ev::BREAK_ALL)

Stops the event loop.

Parameters

int $how

One of the Ev::BREAK_* flags.

suspend()

Suspend the loop.

EvLoop::suspend() and EvLoop::resume() methods suspend and resume a loop correspondingly.

final EvTimer timer(float $after, float $repeat, mixed $callback, mixed $data = null, int $priority = 0)

Creates EvTimer object associated with the current event loop instance.

Parameters

float $after
float $repeat
mixed $callback
mixed $data
int $priority

Return Value

EvTimer

verify()

Performs internal consistency checks (for debugging).

Performs internal consistency checks (for debugging libev) and abort the program if any data structures were found to be corrupted.

static EvLoop defaultLoop(int $flags = Ev::FLAG_AUTO, mixed $data = null, float $io_interval = 0.0, float $timeout_interval = 0.0)

Returns or creates the default event loop.

If the default event loop is not created, EvLoop::defaultLoop() creates it with the specified parameters. Otherwise, it just returns the object representing previously created instance ignoring all the parameters.

Parameters

int $flags
mixed $data
float $io_interval
float $timeout_interval

Return Value

EvLoop