final class Ev (View source)

Ev is a singleton providing access to the default loop and to some common operations.

Constants

FLAG_AUTO

Flag passed to create a loop: The default flags value

FLAG_NOENV

Flag passed to create a loop: If this flag used(or the program runs setuid or setgid), libev won't look at the environment variable LIBEV_FLAGS. Otherwise(by default), LIBEV_FLAGS will override the flags completely if it is found. Useful for performance tests and searching for bugs.

FLAG_FORKCHECK

Flag passed to create a loop: Makes libev check for a fork in each iteration, instead of calling EvLoop::fork() manually. This works by calling getpid() on every iteration of the loop, and thus this might slow down the event loop with lots of loop iterations, but usually is not noticeable. This flag setting cannot be overridden or specified in the LIBEV_FLAGS environment variable.

FLAG_NOINOTIFY

Flag passed to create a loop: When this flag is specified, libev won't attempt to use the inotify API for its ev_stat watchers. The flag can be useful to conserve inotify file descriptors, as otherwise each loop using ev_stat watchers consumes one inotify handle.

FLAG_SIGNALFD

Flag passed to create a loop: When this flag is specified, libev will attempt to use the signalfd API for its ev_signal (and ev_child ) watchers. This API delivers signals synchronously, which makes it both faster and might make it possible to get the queued signal data. It can also simplify signal handling with threads, as long as signals are properly blocked in threads. Signalfd will not be used by default.

FLAG_NOSIGMASK

Flag passed to create a loop: When this flag is specified, libev will avoid to modify the signal mask.

Specifically, this means having to make sure signals are unblocked before receiving them.

This behaviour is useful for custom signal handling, or handling signals only in specific threads.

RUN_NOWAIT

Flag passed to Ev::run() or EvLoop::run(): Means that event loop will look for new events, will handle those events and any already outstanding ones, but will not wait and block the process in case there are no events and will return after one iteration of the loop. This is sometimes useful to poll and handle new events while doing lengthy calculations, to keep the program responsive.

RUN_ONCE

Flag passed to Ev::run() or EvLoop::run(): Means that event loop will look for new events (waiting if necessary) and will handle those and any already outstanding ones. It will block the process until at least one new event arrives (which could be an event internal to libev itself, so there is no guarantee that a user-registered callback will be called), and will return after one iteration of the loop.

BREAK_CANCEL

Flag passed to Ev::stop() or EvLoop::stop(): Cancel the break operation.

BREAK_ONE

Flag passed to Ev::stop() or EvLoop::stop(): Makes the innermost Ev::run() or EvLoop::run() call return.

BREAK_ALL

Flag passed to Ev::stop() or EvLoop::stop(): Makes all nested Ev::run() or EvLoop::run() calls return.

MINPRI

Lowest allowed watcher priority.

MAXPRI

Highest allowed watcher priority.

READ

Event bitmask: The file descriptor in the EvIo watcher has become readable.

WRITE

Event bitmask: The file descriptor in the EvIo watcher has become writable.

TIMER

Event bitmask: EvTimer watcher has been timed out.

PERIODIC

Event bitmask: EvPeriodic watcher has been timed out.

SIGNAL

Event bitmask: A signal specified in EvSignal::__construct() has been received.

CHILD

Event bitmask: The pid specified in EvChild::__construct() has received a status change.

STAT

Event bitmask: The path specified in EvStat watcher changed its attributes.

IDLE

Event bitmask: EvIdle watcher works when there is nothing to do with other watchers.

PREPARE

Event bitmask: All EvPrepare watchers are invoked just before Ev::run() starts. Thus, EvPrepare watchers are the last watchers invoked before the event loop sleeps or polls for new events.

CHECK

Event bitmask: All EvCheck watchers are queued just after Ev::run() has gathered the new events, but before it queues any callbacks for any received events. Thus, EvCheck watchers will be invoked before any other watchers of the same or lower priority within an event loop iteration.

EMBED

Event bitmask: The embedded event loop specified in the EvEmbed watcher needs attention.

CUSTOM

Event bitmask: Not ever sent(or otherwise used) by libev itself, but can be freely used by libev users to signal watchers (e.g. via EvWatcher::feed() ).

ERROR

Event bitmask: An unspecified error has occurred, the watcher has been stopped. This might happen because the watcher could not be properly started because libev ran out of memory, a file descriptor was found to be closed or any other problem. Libev considers these application bugs.

BACKEND_SELECT

select(2) backend

BACKEND_POLL

poll(2) backend

BACKEND_EPOLL

Linux-specific epoll(7) backend for both pre- and post-2.6.9 kernels

BACKEND_KQUEUE

kqueue backend used on most BSD systems. EvEmbed watcher could be used to embed one loop(with kqueue backend) into another. For instance, one can try to create an event loop with kqueue backend and use it for sockets only.

BACKEND_DEVPOLL

Solaris 8 backend. This is not implemented yet.

BACKEND_PORT

Solaris 10 event port mechanism with a good scaling.

BACKEND_ALL

Try all backends(even currupted ones). It's not recommended to use it explicitly. Bitwise operators should be applied here(e.g. Ev::BACKEND_ALL & ~ Ev::BACKEND_KQUEUE ) Use Ev::recommendedBackends() , or don't specify any backends at all.

BACKEND_MASK

Not a backend, but a mask to select all backend bits from flags value to mask out any backends(e.g. when modifying the LIBEV_FLAGS environment variable).

Methods

static int
backend()

Returns an integer describing the backend used by libev.

static int
depth()

Returns recursion depth

static int
embeddableBackends()

Returns the set of backends that are embeddable in other event loops.

static 
feedSignal(int $signum)

Feed signal event into Ev

static 
feedSignalEvent(int $signum)

Feed signal event into the default loop

static int
iteration()

Return the number of times the default event loop has polled for new events.

static float
now()

Returns the time when the last iteration of the default event loop has started.

static 
nowUpdate()

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

static int
recommendedBackends()

Returns a bit mask of recommended backends for current platform.

static 
resume()

Resume previously suspended default event loop.

static 
run(int $flags = self::FLAG_AUTO)

Begin checking for events and calling callbacks for the default loop.

static 
sleep(float $seconds)

Block the process for the given number of seconds.

static 
stop(int $how = self::BREAK_ONE)

Stops the default event loop

static int
supportedBackends()

Returns the set of backends supported by current libev configuration.

static 
suspend()

Suspend the default event loop.

static float
time()

Returns the current time in fractional seconds since the epoch.

static 
verify()

Performs internal consistency checks (for debugging).

Details

final static int backend()

Returns an integer describing the backend used by libev.

Returns an integer describing the backend used by libev. See Ev::BACKEND_* flags

Return Value

int

Bit mask describing the backend used by libev, see Ev::BACKEND_* flags.

final static int depth()

Returns recursion depth

The number of times Ev::run() was entered minus the number of times Ev::run() was exited normally, in other words, the recursion depth. Outside Ev::run() , this number is 0 . In a callback, this number is 1 , unless Ev::run() was invoked recursively (or from another thread), in which case it is higher.

Return Value

int

Recursion depth of the default loop.

final static int embeddableBackends()

Returns the set of backends that are embeddable in other event loops.

Return Value

int

Bit mask which can contain Ev::BACKEND_* flags combined using bitwise OR operator.

final static feedSignal(int $signum)

Feed signal event into Ev

Simulates a signal receive. It is safe to call this function at any time, from any context, including signal handlers or random threads. Its main use is to customise signal handling in the process.

Unlike Ev::feedSignalEvent() , this works regardless of which loop has registered the signal.

Parameters

int $signum

Signal number. See signal(7) man page for details. You can use constants exported by pcntl extension.

final static feedSignalEvent(int $signum)

Feed signal event into the default loop

Feed signal event into the default loop. Ev will react to this call as if the signal specified by signal had occurred.

Parameters

int $signum

Signal number. See signal(7) man page for details. See also constants exported by pcntl extension.

final static int iteration()

Return the number of times the default event loop has polled for new events.

Return the number of times the event loop has polled for new events. Sometimes useful as a generation counter.

Return Value

int

Number of polls of the default event loop.

final static float now()

Returns the time when the last iteration of the default event loop has started.

Returns the time when the last iteration of the default event loop has started. This is the time that timers (EvTimer and EvPeriodic) are based on, and referring to it is usually faster then calling Ev::time().

Return Value

float

Number of seconds(fractional) representing the time when the last iteration of the default event loop has started.

final static 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 static int recommendedBackends()

Returns a bit mask of recommended backends for current platform.

Returns the set of all backends compiled into this binary of libev and also recommended for this platform, meaning it will work for most file descriptor types. This set is often smaller than the one returned by Ev::supportedBackends(), as for example kqueue is broken on most BSD systems and will not be auto-detected unless it is requested explicitly. This is the set of backends that libev will probe with no backends specified explicitly.

Return Value

int

Bit mask which can contain Ev::BACKEND_* flags combined using bitwise OR operator.

final static resume()

Resume previously suspended default event loop.

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

All timer watchers will be delayed by the time spend between suspend and resume , and all periodic watchers will be rescheduled(that is, they will lose any events that would have occurred while suspended).

After calling Ev::suspend() it is not allowed to call any function on the given loop other than Ev::resume(). Also it is not allowed to call Ev::resume() without a previous call to Ev::suspend().

Calling suspend / resume has the side effect of updating the event loop time (see Ev::nowUpdate()).

final static run(int $flags = self::FLAG_AUTO)

Begin checking for events and calling callbacks for the default loop.

Begin checking for events and calling callbacks for the default 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::FLAG_* flags

final static sleep(float $seconds)

Block the process for the given number of seconds.

Parameters

float $seconds

Fractional number of seconds

final static stop(int $how = self::BREAK_ONE)

Stops the default event loop

Parameters

int $how

One of the Ev::BREAK_* constants

final static int supportedBackends()

Returns the set of backends supported by current libev configuration.

Return Value

int

Bit mask which can contain Ev::BACKEND_* flags combined using bitwise OR operator.

final static suspend()

Suspend the default event loop.

Ev::suspend() and Ev::resume() methods suspend and resume the default loop correspondingly.

All timer watchers will be delayed by the time spend between suspend and resume , and all periodic watchers will be rescheduled(that is, they will lose any events that would have occurred while suspended).

After calling Ev::suspend() it is not allowed to call any function on the given loop other than Ev::resume(). Also it is not allowed to call Ev::resume() without a previous call to Ev::suspend().

final static float time()

Returns the current time in fractional seconds since the epoch.

Returns the current time in fractional seconds since the epoch. Consider using Ev::now()

Return Value

float

The current time in fractional seconds since the epoch.

final static 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.