Ev

目录

简介

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

类摘要

Ev

final class Ev {

/* Constants */

const integer Ev::FLAG_AUTO = 0 ;

const integer Ev::FLAG_NOENV = 16777216 ;

const integer Ev::FLAG_FORKCHECK = 33554432 ;

const integer Ev::FLAG_NOINOTIFY = 1048576 ;

const integer Ev::FLAG_SIGNALFD = 2097152 ;

const integer Ev::FLAG_NOSIGMASK = 4194304 ;

const integer Ev::RUN_NOWAIT = 1 ;

const integer Ev::RUN_ONCE = 2 ;

const integer Ev::BREAK_CANCEL = 0 ;

const integer Ev::BREAK_ONE = 1 ;

const integer Ev::BREAK_ALL = 2 ;

const integer Ev::MINPRI = -2 ;

const integer Ev::MAXPRI = 2 ;

const integer Ev::READ = 1 ;

const integer Ev::WRITE = 2 ;

const integer Ev::TIMER = 256 ;

const integer Ev::PERIODIC = 512 ;

const integer Ev::SIGNAL = 1024 ;

const integer Ev::CHILD = 2048 ;

const integer Ev::STAT = 4096 ;

const integer Ev::IDLE = 8192 ;

const integer Ev::PREPARE = 16384 ;

const integer Ev::CHECK = 32768 ;

const integer Ev::EMBED = 65536 ;

const integer Ev::CUSTOM = 16777216 ;

const integer Ev::ERROR = 2147483648 ;

const integer Ev::BACKEND_SELECT = 1 ;

const integer Ev::BACKEND_POLL = 2 ;

const integer Ev::BACKEND_EPOLL = 4 ;

const integer Ev::BACKEND_KQUEUE = 8 ;

const integer Ev::BACKEND_DEVPOLL = 16 ;

const integer Ev::BACKEND_PORT = 32 ;

const integer Ev::BACKEND_ALL = 63 ;

const integer Ev::BACKEND_MASK = 65535 ;

/* 方法 */

final public static int backend ( void )

final public static int depth ( void )

final public static int embeddableBackends ( void )

final public static void feedSignal ( int $signum )

final public static void feedSignalEvent ( int $signum )

final public static int iteration ( void )

final public static float now ( void )

final public static void nowUpdate ( void )

final public static int recommendedBackends ( void )

final public static void resume ( void )

final public static void run ([ int $flags ] )

final public static void sleep ( float $seconds )

final public static void stop ([ int $how ] )

final public static int supportedBackends ( void )

final public static void suspend ( void )

final public static float time ( void )

final public static void verify ( void )

}

预定义常量

Flags passed to create a loop:

Ev::FLAG_AUTO
The default flags value

Ev::FLAG_NOENV
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.

Ev::FLAG_FORKCHECK
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.

Ev::FLAG_NOINOTIFY
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.

Ev::FLAG_SIGNALFD
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.

Ev::FLAG_NOSIGMASK
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.

Flags passed to Ev::run , or EvLoop::run

Ev::RUN_NOWAIT
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.

Ev::RUN_ONCE
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.

Flags passed to Ev::stop , or EvLoop::stop

Ev::BREAK_CANCEL
Cancel the break operation.

Ev::BREAK_ONE
Makes the innermost Ev::run (or EvLoop::run ) call return.

Ev::BREAK_ALL
Makes all nested Ev::run (or EvLoop::run ) calls return.

Watcher priorities:

Ev::MINPRI
Minimum allowed watcher priority.

Ev::MAXPRI
Maximum allowed watcher priority.

Bit masks of (received) events:

Ev::READ
The file descriptor in the EvIo watcher has become readable.

Ev::WRITE
The file descriptor in the EvIo watcher has become writable.

Ev::TIMER
EvTimer watcher has been timed out.

Ev::PERIODIC
EvPeriodic watcher has been timed out.

Ev::SIGNAL
A signal specified in EvSignal::__construct has been received.

Ev::CHILD
The pid specified in EvChild::__construct has received a status change.

Ev::STAT
The path specified in EvStat watcher changed its attributes.

Ev::IDLE
EvIdle watcher works when there is nothing to do with other watchers.

Ev::PREPARE
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.

Ev::CHECK
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.

Ev::EMBED
The embedded event loop specified in the EvEmbed watcher needs attention.

Ev::CUSTOM
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 ).

Ev::ERROR
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. See also » ANATOMY OF A WATCHER

Backend flags:

Ev::BACKEND_SELECT
select(2) backend

Ev::BACKEND_POLL
poll(2) backend

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

Ev::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.

Ev::BACKEND_DEVPOLL
Solaris 8 backend. This is not implemented yet.

Ev::BACKEND_PORT
Solaris 10 event port mechanism with a good scaling.

Ev::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.

Ev::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).

Note:

For the default loop during module initialization phase Ev registers » ev_loop_fork call by means of pthread_atfork (if available).

Note:

There are methods providing access to the default event loop in Ev class(e.g. class="methodname">Ev::iteration , class="methodname">Ev::depth etc.) For custom loops (created with EvLoop::__construct ) these values may be accessed via corresponding properties and methods of the EvLoop class.

The instance of the default event loop itself can be fetched by means of EvLoop::defaultLoop method.

Ev::backend

Returns an integer describing the backend used by libev

说明

final public static int Ev::backend ( void )

Returns an integer describing the backend used by libev . See Backend flags

参数

此函数没有参数。

返回值

Returns an integer(bit mask) describing the backend used by libev .

参见

  • EvEmbed
  • Ev::embeddableBackends
  • Ev::recommendedBackends
  • Ev::supportedBackends
  • Backend flags

Ev::depth

Returns recursion depth

说明

final public static int Ev::depth ( void )

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.

参数

此函数没有参数。

返回值

ev_depth returns recursion depth of the default loop.

参见

  • Ev::iteration

Ev::embeddableBackends

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

说明

final public static int Ev::embeddableBackends ( void )

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

参数

此函数没有参数。

返回值

Returns a bit mask which can containing backend flags combined using bitwise OR operator.

范例

示例 #1 Embedding loop created with kqueue backend into the default loop

<?php
/*
* Check if kqueue is available but not recommended and create a kqueue backend
* for use with sockets (which usually work with any kqueue implementation).
* Store the kqueue/socket-only event loop in loop_socket. (One might optionally
* use EVFLAG_NOENV, too)
*
* Example borrowed from
* http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#Examples_CONTENT-9
*/
$loop        = EvLoop::defaultLoop();
$socket_loop = NULL;
$embed       = NULL;

if (Ev::supportedBackends() & ~Ev::recommendedBackends() & Ev::BACKEND_KQUEUE) {
 if (($socket_loop = new EvLoop(Ev::BACKEND_KQUEUE))) {
  $embed = new EvEmbed($loop);
 }
}

if (!$socket_loop) {
 $socket_loop = $loop;
}

// Now use $socket_loop for all sockets, and $loop for anything else
?>

参见

Ev::feedSignal

Feed a signal event info Ev

说明

final public static void Ev::feedSignal ( int $signum )

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.

参数

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

返回值

没有返回值。

参见

  • Ev::feedSignalEvent

Ev::feedSignalEvent

Feed signal event into the default loop

说明

final public static void Ev::feedSignalEvent ( int $signum )

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

参数

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

返回值

没有返回值。

参见

  • Ev::feedSignal

Ev::iteration

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

说明

final public static int Ev::iteration ( void )

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

参数

此函数没有参数。

返回值

Returns number of polls of the default event loop.

参见

  • Ev::depth

Ev::now

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

说明

final public static float Ev::now ( void )

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 .

参数

此函数没有参数。

返回值

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

参见

  • Ev::nowUpdate

Ev::nowUpdate

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

说明

final public static void Ev::nowUpdate ( void )

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.

参数

此函数没有参数。

返回值

没有返回值。

参见

  • Ev::now

Ev::recommendedBackends

Returns a bit mask of recommended backends for current platform

说明

final public static int Ev::recommendedBackends ( void )

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_supported_backends , 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 no backends specified explicitly.

参数

此函数没有参数。

返回值

Returns a bit mask which can containing backend flags combined using bitwise OR operator.

范例

示例 #1 Embedding one loop into another

<?php
/*
* Try to get an embeddable event loop and embed it into the default event loop.
* If it is impossible, use the default
* loop. The default loop is stored in $loop_hi, while the embeddable loop is
* stored in $loop_lo(which is $loop_hi in the case no embeddable loop can be
* used).
*
* Sample translated to PHP
* http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#Examples_CONTENT-9
*/
$loop_hi = EvLoop::defaultLoop();
$loop_lo = NULL;
$embed   = NULL;

/*
* See if there is a chance of getting one that works
* (flags' value of 0 means autodetection)
*/
$loop_lo = Ev::embeddableBackends() & Ev::recommendedBackends()
 ? new EvLoop(Ev::embeddableBackends() & Ev::recommendedBackends())
 : 0;

if ($loop_lo) {
 $embed = new EvEmbed($loop_lo, function () {});
} else {
 $loop_lo = $loop_hi;
}
?>

参见

Ev::resume

Resume previously suspended default event loop

说明

final public static void Ev::resume ( void )

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 ).

参数

此函数没有参数。

返回值

没有返回值。

参见

  • Ev::suspend

Ev::run

Begin checking for events and calling callbacks for the default loop

说明

final public static void Ev::run ([ int $flags ] )

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 .

参数

flags
Optional parameter flags can be one of the following:

flagsDescription
0The default behavior described above
Ev::RUN_ONCEBlock at most one(wait, but don't loop)
Ev::RUN_NOWAITDon't block at all(fetch/handle events, but don't wait)

See the run flag constants .

返回值

没有返回值。

参见

  • Ev::stop
  • EvLoop::run

Ev::sleep

Block the process for the given number of seconds

说明

final public static void Ev::sleep ( float $seconds )

Block the process for the given number of seconds.

参数

seconds
Fractional number of seconds

返回值

没有返回值。

Ev::stop

Stops the default event loop

说明

final public static void Ev::stop ([ int $how ] )

Stops the default event loop

参数

how
One of Ev::BREAK_* constants .

返回值

没有返回值。

参见

  • Ev::run

Ev::supportedBackends

Returns the set of backends supported by current libev configuration

说明

final public static int Ev::supportedBackends ( void )

Returns the set of backends supported by current libev configuration.

参数

此函数没有参数。

返回值

Returns a bit mask which can containing backend flags combined using bitwise OR operator.

范例

示例 #1 Embedding loop created with kqueue backend into the default loop

<?php
/*
* Check if kqueue is available but not recommended and create a kqueue backend
* for use with sockets (which usually work with any kqueue implementation).
* Store the kqueue/socket-only event loop in loop_socket. (One might optionally
* use EVFLAG_NOENV, too)
*
* Example borrowed from
* http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#Examples_CONTENT-9
*/
$loop        = EvLoop::defaultLoop();
$socket_loop = NULL;
$embed       = NULL;

if (Ev::supportedBackends() & ~Ev::recommendedBackends() & Ev::BACKEND_KQUEUE) {
 if (($socket_loop = new EvLoop(Ev::BACKEND_KQUEUE))) {
  $embed = new EvEmbed($loop);
 }
}

if (!$socket_loop) {
 $socket_loop = $loop;
}

// Now use $socket_loop for all sockets, and $loop for anything else
?>

参见

Ev::suspend

Suspend the default event loop

说明

final public static void Ev::suspend ( void )

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 .

参数

此函数没有参数。

返回值

没有返回值。

参见

  • Ev::resume

Ev::time

Returns the current time in fractional seconds since the epoch

说明

final public static float Ev::time ( void )

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

参数

此函数没有参数。

返回值

Returns the current time in fractional seconds since the epoch.

参见

  • Ev::now

Ev::verify

Performs internal consistency checks(for debugging)

说明

final public static void Ev::verify ( void )

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

参数

此函数没有参数。

返回值

没有返回值。

简介

EvPrepare and EvCheck watchers are usually used in pairs. EvPrepare watchers get invoked before the process blocks, EvCheck afterwards.

It is not allowed to call EvLoop::run or similar methods or functions that enter the current event loop from either EvPrepare or EvCheck watchers. Other loops than the current one are fine, however. The rationale behind this is that one don't need to check for recursion in those watchers, i.e. the sequence will always be: EvPrepare -> blocking -> EvCheck , so having a watcher of each kind they will always be called in pairs bracketing the blocking call.

The main purpose is to integrate other event mechanisms into libev and their use is somewhat advanced. They could be used, for example, to track variable changes, implement custom watchers, integrate net-snmp or a coroutine library and lots more. They are also occasionally useful to cache some data and want to flush it before blocking.

It is recommended to give EvCheck watchers highest( Ev::MAXPRI ) priority, to ensure that they are being run before any other watchers after the poll (this doesn’t matter for EvPrepare watchers).

Also, EvCheck watchers should not activate/feed events. While libev fully supports this, they might get executed before other EvCheck watchers did their job.

类摘要

EvCheck

class EvCheck extends EvWatcher {

/* 继承的属性 */

public $is_active ;

public $data ;

public $is_pending ;

public $priority ;

/* 方法 */

public __construct ( callable $callback [, mixed $data [, int $priority ]] )

final public static object createStopped ( string $callback [, string $data [, string $priority ]] )

/* 继承的方法 */

public int EvWatcher::clear ( void )

abstract public EvWatcher::__construct ( void )

public void EvWatcher::feed ( int $revents )

public EvLoop EvWatcher::getLoop ( void )

public void EvWatcher::invoke ( int $revents )

public bool EvWatcher::keepalive ([ bool $value ] )

public void EvWatcher::setCallback ( callable $callback )

public void EvWatcher::start ( void )

public void EvWatcher::stop ( void )

}

EvCheck::__construct

Constructs the EvCheck watcher object

说明

public EvCheck::__construct ( callable $callback [, mixed $data [, int $priority ]] )

Constructs the EvCheck watcher object.

参数

callback
See Watcher callbacks .

data
Custom data associated with the watcher.

priority
Watcher priority

返回值

Returns EvCheck object on success.

参见

  • EvPrepare
  • EvLoop::check

EvCheck::createStopped

Create instance of a stopped EvCheck watcher

说明

final public static object EvCheck::createStopped ( string $callback [, string $data [, string $priority ]] )

Create instance of a stopped EvCheck watcher

参数

callback
See Watcher callbacks .

data
Custom data associated with the watcher.

priority
Watcher priority

返回值

Returns EvCheck object on success.

参见

  • EvPrepare

简介

EvChild watchers trigger when the process receives a SIGCHLD in response to some child status changes (most typically when a child dies or exits). It is permissible to install an EvChild watcher after the child has been forked(which implies it might have already exited), as long as the event loop isn't entered(or is continued from a watcher), i.e. forking and then immediately registering a watcher for the child is fine, but forking and registering a watcher a few event loop iterations later or in the next callback invocation is not.

It is allowed to register EvChild watchers in the default loop only.

类摘要

EvChild

class EvChild extends EvWatcher {

/* 属性 */

public $pid ;

public $rpid ;

public $rstatus ;

/* 继承的属性 */

public $is_active ;

public $data ;

public $is_pending ;

public $priority ;

/* 方法 */

public __construct ( int $pid , bool $trace , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

final public static object createStopped ( int $pid , bool $trace , callable $callback [, mixed $data [, int $priority ]] )

public void set ( int $pid , bool $trace )

/* 继承的方法 */

public int EvWatcher::clear ( void )

abstract public EvWatcher::__construct ( void )

public void EvWatcher::feed ( int $revents )

public EvLoop EvWatcher::getLoop ( void )

public void EvWatcher::invoke ( int $revents )

public bool EvWatcher::keepalive ([ bool $value ] )

public void EvWatcher::setCallback ( callable $callback )

public void EvWatcher::start ( void )

public void EvWatcher::stop ( void )

}

属性

pid
Readonly . The process ID this watcher watches out for, or 0 , meaning any process ID.

rpid
Readonly .The process ID that detected a status change.

rstatus
Readonly . The process exit status caused by rpid .

EvChild::__construct

Constructs the EvChild watcher object

说明

public EvChild::__construct ( int $pid , bool $trace , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

Constructs the EvChild watcher object.

Call the callback when a status change for process ID pid (or any PID if pid is 0 ) has been received(a status change happens when the process terminates or is killed, or, when trace is TRUE, additionally when it is stopped or continued). In other words, when the process receives a SIGCHLD , Ev will fetch the outstanding exit/wait status for all changed/zombie children and call the callback.

It is valid to install a child watcher after an EvChild has exited but before the event loop has started its next iteration. For example, first one calls fork , then the new child process might exit, and only then an EvChild watcher is installed in the parent for the new PID .

You can access both exit/tracing status and pid by using the rstatus and rpid properties of the watcher object.

The number of PID watchers per PID is unlimited. All of them will be called.

The EvChild::createStopped method doesn't start(activate) the newly created watcher.

参数

pid
Wait for status changes of process PID(or any process if PID is specified as 0 ).

trace
If FALSE, only activate the watcher when the process terminates. Otherwise(TRUE) additionally activate the watcher when the process is stopped or continued.

callback
See Watcher callbacks .

data
Custom data associated with the watcher.

priority
Watcher priority

返回值

Returns EvChild object on success.

参见

  • EvLoop::child

EvChild::createStopped

Create instance of a stopped EvCheck watcher

说明

final public static object EvChild::createStopped ( int $pid , bool $trace , callable $callback [, mixed $data [, int $priority ]] )

The same as EvChild::__construct , but doesn't start the watcher automatically.

参数

pid
The same as for EvChild::__construct

trace
The same as for EvChild::__construct

callback
See Watcher callbacks .

data
Custom data associated with the watcher.

priority
Watcher priority

返回值

参见

  • EvChild::__construct
  • EvLoop::child

EvChild::set

Configures the watcher

说明

public void EvChild::set ( int $pid , bool $trace )

参数

pid
The same as for EvChild::__construct

trace
The same as for EvChild::__construct

返回值

没有返回值。

参见

  • EvChild::__construct

简介

Used to embed one event loop into another.

类摘要

EvEmbed

class EvEmbed extends EvWatcher {

/* 属性 */

public $embed ;

/* 方法 */

public __construct ( object $other [, callable $callback [, mixed $data [, int $priority ]]] )

final public static void createStopped ( object $other [, callable $callback [, mixed $data [, int $priority ]]] )

public void set ( object $other )

public void sweep ( void )

/* 继承的方法 */

public int EvWatcher::clear ( void )

abstract public EvWatcher::__construct ( void )

public void EvWatcher::feed ( int $revents )

public EvLoop EvWatcher::getLoop ( void )

public void EvWatcher::invoke ( int $revents )

public bool EvWatcher::keepalive ([ bool $value ] )

public void EvWatcher::setCallback ( callable $callback )

public void EvWatcher::start ( void )

public void EvWatcher::stop ( void )

}

属性

is_active

data

is_pending

priority

embed

EvEmbed::__construct

Constructs the EvEmbed object

说明

public EvEmbed::__construct ( object $other [, callable $callback [, mixed $data [, int $priority ]]] )

This is a rather advanced watcher type that lets to embed one event loop into another(currently only IO events are supported in the embedded loop, other types of watchers might be handled in a delayed or incorrect fashion and must not be used).

See » the libev documentation for details.

This watcher is most useful on BSD systems without working kqueue to still be able to handle a large number of sockets. See example below.

参数

other
Instance of EvLoop . The loop to embed, this loop must be embeddable(see Ev::embeddableBackends ).

callback
See Watcher callbacks .

data
Custom data associated with the watcher.

priority
Watcher priority

返回值

Returns EvEmbed object on success.

范例

示例 #1 Embedding loop created with kqueue backend into the default loop

<?php
/*
 * Check if kqueue is available but not recommended and create a kqueue backend
 * for use with sockets (which usually work with any kqueue implementation).
 * Store the kqueue/socket-only event loop in loop_socket. (One might optionally
 * use EVFLAG_NOENV, too)
 *
 * Example borrowed from
 * http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#Examples_CONTENT-9
 */
$loop        = EvLoop::defaultLoop();
$socket_loop = NULL;
$embed       = NULL;

if (Ev::supportedBackends() & ~Ev::recommendedBackends() & Ev::BACKEND_KQUEUE) {
    if (($socket_loop = new EvLoop(Ev::BACKEND_KQUEUE))) {
        $embed = new EvEmbed($loop);
    }
}

if (!$socket_loop) {
    $socket_loop = $loop;
}

// Now use $socket_loop for all sockets, and $loop for anything else
?>

参见

  • Ev::embeddableBackends

EvEmbed::createStopped

Create stopped EvEmbed watcher object

说明

final public static void EvEmbed::createStopped ( object $other [, callable $callback [, mixed $data [, int $priority ]]] )

The same as EvEmbed::__construct , but doesn't start the watcher automatically.

参数

other
The same as for EvEmbed::__construct

callback
See Watcher callbacks .

data
Custom data associated with the watcher.

priority
Watcher priority

返回值

Returns stopped EvEmbed object on success.

参见

  • EvEmbed::__construct
  • Ev::embeddableBackends

EvEmbed::set

Configures the watcher

说明

public void EvEmbed::set ( object $other )

Configures the watcher to use other event loop object.

参数

other
The same as for EvEmbed::__construct

返回值

没有返回值。

EvEmbed::sweep

Make a single, non-blocking sweep over the embedded loop

说明

public void EvEmbed::sweep ( void )

Make a single, non-blocking sweep over the embedded loop. Works similarly to the following, but in the most appropriate way for embedded loops:

<?php
$other->start(Ev::RUN_NOWAIT);
?>

参数

此函数没有参数。

返回值

没有返回值。

参见

  • EvWatcher::start

简介

Fork watchers are called when a fork() was detected (usually because whoever signalled libev about it by calling EvLoop::fork ). The invocation is done before the event loop blocks next and before EvCheck watchers are being called, and only in the child after the fork. Note, that if whoever calling EvLoop::fork calls it in the wrong process, the fork handlers will be invoked, too.

类摘要

EvFork

class EvFork extends EvWatcher {

/* 继承的属性 */

public $is_active ;

public $data ;

public $is_pending ;

public $priority ;

/* 方法 */

public __construct ( callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

final public static object createStopped ( string $callback [, string $data [, string $priority ]] )

/* 继承的方法 */

public int EvWatcher::clear ( void )

abstract public EvWatcher::__construct ( void )

public void EvWatcher::feed ( int $revents )

public EvLoop EvWatcher::getLoop ( void )

public void EvWatcher::invoke ( int $revents )

public bool EvWatcher::keepalive ([ bool $value ] )

public void EvWatcher::setCallback ( callable $callback )

public void EvWatcher::start ( void )

public void EvWatcher::stop ( void )

}

EvFork::__construct

Constructs the EvFork watcher object

说明

public EvFork::__construct ( callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

Constructs the EvFork watcher object and starts the watcher automatically.

参数

callback
See Watcher callbacks .

data
Custom data associated with the watcher.

priority
Watcher priority

返回值

Returns EvFork object on success.

参见

  • EvLoop::fork
  • EvCheck

EvFork::createStopped

Creates a stopped instance of EvFork watcher class

说明

final public static object EvFork::createStopped ( string $callback [, string $data [, string $priority ]] )

The same as EvFork::__construct , but doesn't start the watcher automatically.

参数

callback
See Watcher callbacks .

data
Custom data associated with the watcher.

priority
Watcher priority

返回值

Returns EvFork(stopped) object on success.

参见

  • EvFork::__construct

简介

EvIdle watchers trigger events when no other events of the same or higher priority are pending ( EvPrepare , EvCheck and other EvIdle watchers do not count as receiving events ).

Thus, as long as the process is busy handling sockets or timeouts(or even signals) of the same or higher priority it will not be triggered. But when the process is in idle(or only lower-priority watchers are pending), the EvIdle watchers are being called once per event loop iteration - until stopped, that is, or the process receives more events and becomes busy again with higher priority stuff.

Apart from keeping the process non-blocking(which is a useful on its own sometimes), EvIdle watchers are a good place to do "pseudo-background processing" , or delay processing stuff to after the event loop has handled all outstanding events.

The most noticeable effect is that as long as any idle watchers are active, the process will not block when waiting for new events.

类摘要

EvIdle

class EvIdle extends EvWatcher {

/* 继承的属性 */

public $is_active ;

public $data ;

public $is_pending ;

public $priority ;

/* 方法 */

public __construct ( callable $callback [, mixed $data [, int $priority ]] )

final public static object createStopped ( string $callback [, mixed $data [, int $priority ]] )

/* 继承的方法 */

public int EvWatcher::clear ( void )

abstract public EvWatcher::__construct ( void )

public void EvWatcher::feed ( int $revents )

public EvLoop EvWatcher::getLoop ( void )

public void EvWatcher::invoke ( int $revents )

public bool EvWatcher::keepalive ([ bool $value ] )

public void EvWatcher::setCallback ( callable $callback )

public void EvWatcher::start ( void )

public void EvWatcher::stop ( void )

}

EvIdle::__construct

Constructs the EvIdle watcher object

说明

public EvIdle::__construct ( callable $callback [, mixed $data [, int $priority ]] )

Constructs the EvIdle watcher object and starts the watcher automatically.

参数

callback
See Watcher callbacks .

data
Custom data associated with the watcher.

priority
Watcher priority

返回值

Returns EvIdle object on success.

参见

  • EvIdle::createStopped
  • EvLoop::idle

EvIdle::createStopped

Creates instance of a stopped EvIdle watcher object

说明

final public static object EvIdle::createStopped ( string $callback [, mixed $data [, int $priority ]] )

The same as EvIdle::__construct , but doesn't start the watcher automatically.

参数

callback
See Watcher callbacks .

data
Custom data associated with the watcher.

priority
Watcher priority

返回值

Returns EvIdle object on success.

参见

  • EvIdle::__construct
  • EvLoop::idle

简介

EvIo watchers check whether a file descriptor(or socket, or a stream castable to numeric file descriptor) is readable or writable in each iteration of the event loop, or, more precisely, when reading would not block the process and writing would at least be able to write some data. This behaviour is called level-triggering because events are kept receiving as long as the condition persists. To stop receiving events just stop the watcher.

The number of read and/or write event watchers per fd is unlimited. Setting all file descriptors to non-blocking mode is also usually a good idea(but not required).

Another thing to watch out for is that it is quite easy to receive false readiness notifications, i.e. the callback might be called with Ev::READ but a subsequent read() will actually block because there is no data. It is very easy to get into this situation. Thus it is best to always use non-blocking I/O: An extra read() returning EAGAIN (or similar) is far preferable to a program hanging until some data arrives.

If for some reason it is impossible to run the fd in non-blocking mode, then separately re-test whether a file descriptor is really ready. Some people additionally use SIGALRM and an interval timer, just to be sure thry won't block infinitely.

Always consider using non-blocking mode.

类摘要

EvIo

class EvIo extends EvWatcher {

/* 属性 */

public $fd ;

public $events ;

/* 继承的属性 */

public $is_active ;

public $data ;

public $is_pending ;

public $priority ;

/* 方法 */

public __construct ( mixed $fd , int $events , callable $callback [, mixed $data [, int $priority ]] )

final public static EvIo createStopped ( mixed $fd , int $events , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

public void set ( mixed $fd , int $events )

/* 继承的方法 */

public int EvWatcher::clear ( void )

abstract public EvWatcher::__construct ( void )

public void EvWatcher::feed ( int $revents )

public EvLoop EvWatcher::getLoop ( void )

public void EvWatcher::invoke ( int $revents )

public bool EvWatcher::keepalive ([ bool $value ] )

public void EvWatcher::setCallback ( callable $callback )

public void EvWatcher::start ( void )

public void EvWatcher::stop ( void )

}

属性

fd

events

EvIo::__construct

Constructs EvIo watcher object

说明

public EvIo::__construct ( mixed $fd , int $events , callable $callback [, mixed $data [, int $priority ]] )

Constructs EvIo watcher object and starts the watcher automatically.

参数

fd
Can be a stream opened with fopen or similar functions, numeric file descriptor, or socket.

events
Ev::READ and/or Ev::WRITE . See the bit masks .

callback
See Watcher callbacks .

data
Custom data associated with the watcher.

priority
Watcher priority

返回值

Returns EvIo object on success.

参见

  • EvIo::createStopped
  • EvLoop::io

EvIo::createStopped

Create stopped EvIo watcher object

说明

final public static EvIo EvIo::createStopped ( mixed $fd , int $events , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

The same as EvIo::__construct , but doesn't start the watcher automatically.

参数

fd
The same as for EvIo::__construct

events
The same as for EvIo::__construct

callback
See Watcher callbacks .

data
Custom data associated with the watcher.

priority
Watcher priority

返回值

Returns EvIo object on success.

参见

  • EvIo::__construct
  • EvLoop::io

EvIo::set

Configures the watcher

说明

public void EvIo::set ( mixed $fd , int $events )

Configures the EvIo watcher

参数

fd
The same as for EvIo::__construct

events
The same as for EvIo::__construct

返回值

没有返回值。

简介

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

类摘要

EvLoop

final class EvLoop {

/* 属性 */

public $data ;

public $backend ;

public $is_default_loop ;

public $iteration ;

public $pending ;

public $io_interval ;

public $timeout_interval ;

public $depth ;

/* 方法 */

public int backend ( void )

final public EvCheck check ( string $callback [, string $data [, string $priority ]] )

final public EvChild child ( string $pid , string $trace , string $callback [, string $data [, string $priority ]] )

public __construct ([ int $flags [, mixed $data = NULL [, float $io_interval = 0.0 [, float $timeout_interval = 0.0 ]]]] )

public static EvLoop defaultLoop ([ int $flags = Ev::FLAG_AUTO [, mixed $data = NULL [, float $io_interval = 0. [, float $timeout_interval = 0. ]]]] )

final public EvEmbed embed ( string $other [, string $callback [, string $data [, string $priority ]]] )

final public EvFork fork ( callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

final public EvIdle idle ( callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

public void invokePending ( void )

final public EvIo io ( mixed $fd , int $events , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

public void loopFork ( void )

public float now ( void )

public void nowUpdate ( void )

final public EvPeriodic periodic ( float $offset , float $interval , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

final public EvPrepare prepare ( callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

public void resume ( void )

public void run ([ int $flags = 0 ] )

final public EvSignal signal ( int $signum , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

final public EvStat stat ( string $path , float $interval , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

public void stop ([ int $how ] )

public void suspend ( void )

final public EvTimer timer ( float $after , float $repeat , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

public void verify ( void )

}

属性

data
Custom data attached to loop

backend
Readonly . The backend flags indicating the event backend in use.

is_default_loop
Readonly . TRUE if it is the default event loop.

iteration
The current iteration count of the loop. See Ev::iteration

pending
The number of pending watchers. 0 indicates that there are no watchers pending.

io_interval
Higher io_interval allows libev to spend more time collecting EvIo events, so more events can be handled per iteration, at the cost of increasing latency. Timeouts (both EvPeriodic and EvTimer ) will not be affected. Setting this to a non-zero value will introduce an additional sleep() call into most loop iterations. The sleep time ensures that libev will not poll for EvIo events more often than once per this interval, on average. Many programs can usually benefit by setting the io_interval to a value near 0.1 , which is often enough for interactive servers(not for games). It usually doesn't make much sense to set it to a lower value than 0.01 , as this approaches the timing granularity of most systems.

See also » FUNCTIONS CONTROLLING EVENT LOOPS .

timeout_interval
Higher timeout_interval allows libev to spend more time collecting timeouts, at the expense of increased latency/jitter/inexactness(the watcher callback will be called later). EvIo watchers will not be affected. Setting this to a non-null value will not introduce any overhead in libev . See also » FUNCTIONS CONTROLLING EVENT LOOPS .

depth
The recursion depth. See Ev::depth .

EvLoop::backend

Returns an integer describing the backend used by libev

说明

public int EvLoop::backend ( void )

The same as Ev::backend , but for the loop instance.

参数

此函数没有参数。

返回值

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

参见

  • Ev::backend

EvLoop::check

Creates EvCheck object associated with the current event loop instance

说明

final public EvCheck EvLoop::check ( string $callback [, string $data [, string $priority ]] )

Creates EvCheck object associated with the current event loop instance.

参数

All parameters have the same meaning as for EvCheck::__construct

返回值

Returns EvCheck object on success.

参见

  • EvCheck::__construct

EvLoop::child

Creates EvChild object associated with the current event loop

说明

final public EvChild EvLoop::child ( string $pid , string $trace , string $callback [, string $data [, string $priority ]] )

Creates EvChild object associated with the current event loop.

参数

All parameters have the same meaning as for EvChild::__construct

返回值

Returns EvChild object on success.

参见

  • EvChild::__construct

EvLoop::__construct

Constructs the event loop object

说明

public EvLoop::__construct ([ int $flags [, mixed $data = NULL [, float $io_interval = 0.0 [, float $timeout_interval = 0.0 ]]]] )

Constructs the event loop object.

参数

flags
One of the event loop flags

data
Custom data associated with the loop.

io_interval
See io_interval

timeout_interval
See timeout_interval

返回值

Returns new EvLoop object.

参见

  • EvLoop::defaultLoop

EvLoop::defaultLoop

Returns or creates the default event loop

说明

public static EvLoop EvLoop::defaultLoop ([ int $flags = Ev::FLAG_AUTO [, mixed $data = NULL [, float $io_interval = 0. [, float $timeout_interval = 0. ]]]] )

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.

参数

flags
One of the event loop flags

data
Custom data to associate with the loop.

io_collect_interval
See io_interval

timeout_collect_interval
See timeout_interval

返回值

Returns EvLoop object on success.

参见

  • EvLoop::__construct

EvLoop::embed

Creates an instance of EvEmbed watcher associated with the current EvLoop object

说明

final public EvEmbed EvLoop::embed ( string $other [, string $callback [, string $data [, string $priority ]]] )

Creates an instance of EvEmbed watcher associated with the current EvLoop object.

参数

All parameters have the same meaning as for EvEmbed::__construct .

返回值

Returns EvEmbed object on success.

参见

  • EvEmbed::__construct

EvLoop::fork

Creates EvFork watcher object associated with the current event loop instance

说明

final public EvFork EvLoop::fork ( callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

Creates EvFork watcher object associated with the current event loop instance

参数

All parameters have the same meaning as for EvFork::__construct

返回值

Returns EvFork object on success.

参见

  • EvFork::__construct

EvLoop::idle

Creates EvIdle watcher object associated with the current event loop instance

说明

final public EvIdle EvLoop::idle ( callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

Creates EvIdle watcher object associated with the current event loop instance

参数

All the parameters have the same meaning as for EvIdle::__construct

返回值

Returns EvIdle object on success.

参见

  • EvIdle::__construct

EvLoop::invokePending

Invoke all pending watchers while resetting their pending state

说明

public void EvLoop::invokePending ( void )

Invoke all pending watchers while resetting their pending state.

参数

此函数没有参数。

返回值

没有返回值。

EvLoop::io

Create EvIo watcher object associated with the current event loop instance

说明

final public EvIo EvLoop::io ( mixed $fd , int $events , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

Create EvIo watcher object associated with the current event loop instance.

参数

All parameters have the same meaning as for EvIo::__construct

返回值

Returns EvIo object on success.

参见

  • EvIo::__construct

EvLoop::loopFork

Must be called after a fork

说明

public void EvLoop::loopFork ( void )

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 ).

参数

此函数没有参数。

返回值

没有返回值。

EvLoop::now

Returns the current "event loop time"

说明

public float EvLoop::now ( void )

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).

参数

此函数没有参数。

返回值

Returns time of the event loop in (fractional) seconds.

参见

  • Ev::now

EvLoop::nowUpdate

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

说明

public void EvLoop::nowUpdate ( void )

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

参数

此函数没有参数。

返回值

没有返回值。

参见

  • EvLoop::now
  • Ev::nowUpdate

EvLoop::periodic

Creates EvPeriodic watcher object associated with the current event loop instance

说明

final public EvPeriodic EvLoop::periodic ( float $offset , float $interval , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

Creates EvPeriodic watcher object associated with the current event loop instance

参数

All parameters have the same maening as for EvPeriodic::__construct

返回值

Returns EvPeriodic object on success.

参见

  • EvPeriodic::__construct

EvLoop::prepare

Creates EvPrepare watcher object associated with the current event loop instance

说明

final public EvPrepare EvLoop::prepare ( callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

Creates EvPrepare watcher object associated with the current event loop instance

参数

All parameters have the same maening as for EvPrepare

返回值

Returns EvPrepare object on success

参见

  • EvPrepare::__construct

EvLoop::resume

Resume previously suspended default event loop

说明

public void EvLoop::resume ( void )

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

参数

此函数没有参数。

返回值

没有返回值。

参见

  • EvLoop::suspend
  • Ev::resume

EvLoop::run

Begin checking for events and calling callbacks for the loop

说明

public void EvLoop::run ([ int $flags = 0 ] )

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 .

参数

flags
Optional parameter flags can be one of the following:

flagsDescription
0The default behavior described above
Ev::RUN_ONCEBlock at most one(wait, but don't loop)
Ev::RUN_NOWAITDon't block at all(fetch/handle events, but don't wait)

See the run flag constants .

返回值

没有返回值。

参见

  • EvLoop::stop
  • Ev::run

EvLoop::signal

Creates EvSignal watcher object associated with the current event loop instance

说明

final public EvSignal EvLoop::signal ( int $signum , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

Creates EvSignal watcher object associated with the current event loop instance

参数

All parameters have the same meaning as for EvSignal::__construct

返回值

Returns EvSignal object on success

参见

  • EvSignal::__construct

EvLoop::stat

Creates EvStat watcher object associated with the current event loop instance

说明

final public EvStat EvLoop::stat ( string $path , float $interval , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

Creates EvStat watcher object associated with the current event loop instance

参数

All parameters have the same meaning as for EvSignal::__construct

返回值

Returns EvStat object on success

参见

  • EvSignal::__construct

EvLoop::stop

Stops the event loop

说明

public void EvLoop::stop ([ int $how ] )

Stops the event loop

参数

how
One of Ev::BREAK_* constants .

返回值

没有返回值。

参见

  • EvLoop::run
  • Ev::stop

EvLoop::suspend

Suspend the loop

说明

public void EvLoop::suspend ( void )

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

参数

此函数没有参数。

返回值

没有返回值。

参见

  • EvLoop::resume
  • Ev::suspend

EvLoop::timer

Creates EvTimer watcher object associated with the current event loop instance

说明

final public EvTimer EvLoop::timer ( float $after , float $repeat , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

Creates EvTimer watcher object associated with the current event loop instance

参数

All parameters have the same meaning as for EvTimer::__construct

返回值

Returns EvTimer object on success

参见

  • EvTimer::__construct

EvLoop::verify

Performs internal consistency checks(for debugging)

说明

public void EvLoop::verify ( void )

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

参数

此函数没有参数。

返回值

没有返回值。

参见

  • Ev::verify

简介

Periodic watchers are also timers of a kind, but they are very versatile.

Unlike EvTimer , EvPeriodic watchers are not based on real time(or relative time, the physical time that passes) but on wall clock time(absolute time, calendar or clock). The difference is that wall clock time can run faster or slower than real time, and time jumps are not uncommon(e.g. when adjusting it).

EvPeriodic watcher can be configured to trigger after some specific point in time. For example, if an EvPeriodic watcher is configured to trigger "in 10 seconds" (e.g. EvLoop::now + 10.0 , i.e. an absolute time, not a delay), and the system clock is reset to January of the previous year , then it will take a year or more to trigger the event (unlike an EvTimer , which would still trigger roughly 10 seconds after starting it as it uses a relative timeout).

As with timers, the callback is guaranteed to be invoked only when the point in time where it is supposed to trigger has passed. If multiple timers become ready during the same loop iteration then the ones with earlier time-out values are invoked before ones with later time-out values (but this is no longer true when a callback calls EvLoop::run recursively).

类摘要

EvPeriodic

class EvPeriodic extends EvWatcher {

/* 属性 */

public $offset ;

public $interval ;

/* 继承的属性 */

public $is_active ;

public $data ;

public $is_pending ;

public $priority ;

/* 方法 */

public void again ( void )

public float at ( void )

public __construct ( float $offset , string $interval , callable $reschedule_cb , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

final public static EvPeriodic createStopped ( float $offset , float $interval , callable $reschedule_cb , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

public void set ( float $offset , float $interval )

/* 继承的方法 */

public int EvWatcher::clear ( void )

abstract public EvWatcher::__construct ( void )

public void EvWatcher::feed ( int $revents )

public EvLoop EvWatcher::getLoop ( void )

public void EvWatcher::invoke ( int $revents )

public bool EvWatcher::keepalive ([ bool $value ] )

public void EvWatcher::setCallback ( callable $callback )

public void EvWatcher::start ( void )

public void EvWatcher::stop ( void )

}

属性

offset
When repeating, this contains the offset value, otherwise this is the absolute point in time(the offset value passed to EvPeriodic::set , although libev might modify this value for better numerical stability).

interval
The current interval value. Can be modified any time, but changes only take effect when the periodic timer fires or EvPeriodic::again is being called.

EvPeriodic::again

Simply stops and restarts the periodic watcher again

说明

public void EvPeriodic::again ( void )

Simply stops and restarts the periodic watcher again. This is only useful when attributes are changed.

参数

此函数没有参数。

返回值

没有返回值。

参见

  • EvTimer::again

EvPeriodic::at

Returns the absolute time that this watcher is supposed to trigger next

说明

public float EvPeriodic::at ( void )

When the watcher is active, returns the absolute time that this watcher is supposed to trigger next. This is not the same as the offset argument to EvPeriodic::set or EvPeriodic::__construct , but indeed works even in interval mode.

参数

此函数没有参数。

返回值

Returns the absolute time this watcher is supposed to trigger next in seconds.

EvPeriodic::__construct

Constructs EvPeriodic watcher object

说明

public EvPeriodic::__construct ( float $offset , string $interval , callable $reschedule_cb , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

Constructs EvPeriodic watcher object and starts it automatically. EvPeriodic::createStopped method creates stopped periodic watcher.

参数

offset
See Periodic watcher operation modes

interval
See Periodic watcher operation modes

reschedule_cb
Reschedule callback. You can pass NULL. See Periodic watcher operation modes

callback
See Watcher callbacks .

data
Custom data associated with the watcher.

priority
Watcher priority

返回值

Returns EvPeriodic object on success.

范例

示例 #1 Periodic timer. Use reschedule callback

<?php
// Tick each 10.5 seconds

function reschedule_cb ($watcher, $now) {
 return $now + (10.5. - fmod($now, 10.5));
}

$w = new EvPeriodic(0., 0., "reschedule_cb", function ($w, $revents) {
 echo time(), PHP_EOL;
});
Ev::run();
?>

示例 #2 Periodic timer. Tick every 10.5 seconds starting at now

<?php
// Tick every 10.5 seconds starting at now
$w = new EvPeriodic(fmod(Ev::now(), 10.5), 10.5, NULL, function ($w, $revents) {
 echo time(), PHP_EOL;
});
Ev::run();
?>

示例 #3 Hourly watcher

<?php
$hourly = EvPeriodic(0, 3600, NULL, function () {
 echo "once per hour\n";
});
?>

参见

EvPeriodic::createStopped

Create a stopped EvPeriodic watcher

说明

final public static EvPeriodic EvPeriodic::createStopped ( float $offset , float $interval , callable $reschedule_cb , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

Create EvPeriodic object. Unlike EvPeriodic::__construct this method doesn't start the watcher automatically.

参数

offset
See Periodic watcher operation modes

interval
See Periodic watcher operation modes

reschedule_cb
Reschedule callback. You can pass NULL. See Periodic watcher operation modes

callback
See Watcher callbacks .

data
Custom data associated with the watcher.

priority
Watcher priority

返回值

Returns EvPeriodic watcher object on success.

参见

  • EvPeriodic::__construct
  • EvTimer::createStopped

EvPeriodic::set

Configures the watcher

说明

public void EvPeriodic::set ( float $offset , float $interval )

(Re-)Configures EvPeriodic watcher

参数

offset
The same meaning as for EvPeriodic::__construct . See Periodic watcher operation modes

interval
The same meaning as for EvPeriodic::__construct . See Periodic watcher operation modes

返回值

没有返回值。

简介

EvPrepare and EvCheck watchers are usually used in pairs. EvPrepare watchers get invoked before the process blocks, EvCheck afterwards.

It is not allowed to call EvLoop::run or similar methods or functions that enter the current event loop from either EvPrepare or EvCheck watchers. Other loops than the current one are fine, however. The rationale behind this is that one don't need to check for recursion in those watchers, i.e. the sequence will always be: EvPrepare -> blocking -> EvCheck , so having a watcher of each kind they will always be called in pairs bracketing the blocking call.

The main purpose is to integrate other event mechanisms into libev and their use is somewhat advanced. They could be used, for example, to track variable changes, implement custom watchers, integrate net-snmp or a coroutine library and lots more. They are also occasionally useful to cache some data and want to flush it before blocking.

It is recommended to give EvCheck watchers highest( Ev::MAXPRI ) priority, to ensure that they are being run before any other watchers after the poll (this doesn’t matter for EvPrepare watchers).

Also, EvCheck watchers should not activate/feed events. While libev fully supports this, they might get executed before other EvCheck watchers did their job.

类摘要

EvPrepare

class EvPrepare extends EvWatcher {

/* 继承的属性 */

public $is_active ;

public $data ;

public $is_pending ;

public $priority ;

/* 方法 */

public __construct ( string $callback [, string $data [, string $priority ]] )

final public static EvPrepare createStopped ( callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

/* 继承的方法 */

public int EvWatcher::clear ( void )

abstract public EvWatcher::__construct ( void )

public void EvWatcher::feed ( int $revents )

public EvLoop EvWatcher::getLoop ( void )

public void EvWatcher::invoke ( int $revents )

public bool EvWatcher::keepalive ([ bool $value ] )

public void EvWatcher::setCallback ( callable $callback )

public void EvWatcher::start ( void )

public void EvWatcher::stop ( void )

}

EvPrepare::__construct

Constructs EvPrepare watcher object

说明

public EvPrepare::__construct ( string $callback [, string $data [, string $priority ]] )

Constructs EvPrepare watcher object. And starts the watcher automatically. If need a stopped watcher consider using EvPrepare::createStopped

参数

callback
See Watcher callbacks .

data
Custom data associated with the watcher.

priority
Watcher priority

返回值

Returns EvPrepare object on success.

参见

  • EvCheck

EvPrepare::createStopped

Creates a stopped instance of EvPrepare watcher

说明

final public static EvPrepare EvPrepare::createStopped ( callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

Creates a stopped instance of EvPrepare watcher. Unlike EvPrepare::__construct , this method doesn' start the watcher automatically.

参数

callback
See Watcher callbacks .

data
Custom data associated with the watcher.

priority
Watcher priority

返回值

Return EvPrepare object on success.

参见

  • EvPrepare::__construct
  • EvWatcher::start

简介

EvSignal watchers will trigger an event when the process receives a specific signal one or more times. Even though signals are very asynchronous, libev will try its best to deliver signals synchronously, i.e. as part of the normal event processing, like any other event.

There is no limit for the number of watchers for the same signal, but only within the same loop, i.e. one can watch for SIGINT in the default loop and for SIGIO in another loop, but it is not allowed to watch for SIGINT in both the default loop and another loop at the same time. At the moment, SIGCHLD is permanently tied to the default loop.

If possible and supported, libev will install its handlers with SA_RESTART (or equivalent) behaviour enabled, so system calls should not be unduly interrupted. In case of a problem with system calls getting interrupted by signals, all the signals can be blocked in an EvCheck watcher and unblocked in a EvPrepare watcher.

类摘要

EvSignal

class EvSignal extends EvWatcher {

/* 属性 */

public $signum ;

/* 继承的属性 */

public $is_active ;

public $data ;

public $is_pending ;

public $priority ;

/* 方法 */

public __construct ( int $signum , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

final public static EvSignal createStopped ( int $signum , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

public void set ( int $signum )

/* 继承的方法 */

public int EvWatcher::clear ( void )

abstract public EvWatcher::__construct ( void )

public void EvWatcher::feed ( int $revents )

public EvLoop EvWatcher::getLoop ( void )

public void EvWatcher::invoke ( int $revents )

public bool EvWatcher::keepalive ([ bool $value ] )

public void EvWatcher::setCallback ( callable $callback )

public void EvWatcher::start ( void )

public void EvWatcher::stop ( void )

}

属性

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

EvSignal::__construct

Constructs EvSignal watcher object

说明

public EvSignal::__construct ( int $signum , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

Constructs EvSignal watcher object and starts it automatically. For a stopped periodic watcher consider using EvSignal::createStopped method.

参数

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

callback
See Watcher callbacks .

data
Custom data associated with the watcher.

priority
Watcher priority

返回值

Returns EvSignal object on success.

范例

示例 #1 Handle SIGTERM signal

<?php
$w = new EvSignal(SIGTERM, function ($watcher) {
    echo "SIGTERM received\n";
    $watcher->stop();
});

Ev::run();
?>

参见

  • EvSignal::createStopped

EvSignal::createStopped

Create stopped EvSignal watcher object

说明

final public static EvSignal EvSignal::createStopped ( int $signum , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

Create stopped EvSignal watcher object. Unlike EvSignal::__construct , this method does't start the watcher automatically.

参数

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

callback
See Watcher callbacks .

data
Custom data associated with the watcher.

priority
Watcher priority

返回值

Returns EvSignal object on success.

参见

  • EvWatcher::start
  • EvSignal::__construct

EvSignal::set

Configures the watcher

说明

public void EvSignal::set ( int $signum )

Configures the watcher.

参数

signum
Signal number. The same as for EvSignal::__construct

返回值

没有返回值。

简介

EvStat monitors a file system path for attribute changes. It calls stat() on that path in regular intervals(or when the OS signals it changed) and sees if it changed compared to the last time, invoking the callback if it did.

The path does not need to exist: changing from "path exists" to "path does not exist" is a status change like any other. The condition "path does not exist" is signified by the 'nlink' item being 0(returned by EvStat::attr method).

The path must not end in a slash or contain special components such as '.' or .. . The path should be absolute: if it is relative and the working directory changes, then the behaviour is undefined.

Since there is no portable change notification interface available, the portable implementation simply calls stat() regularly on the path to see if it changed somehow. For this case a recommended polling interval can be specified. If one specifies a polling interval of 0.0 (highly recommended) then a suitable, unspecified default value will be used(which could be expected to be around 5 seconds, although this might change dynamically). libev will also impose a minimum interval which is currently around 0.1 , but that’s usually overkill.

This watcher type is not meant for massive numbers of EvStat watchers, as even with OS-supported change notifications, this can be resource-intensive.

类摘要

EvStat

class EvStat extends EvWatcher {

/* 属性 */

public $path ;

public $interval ;

/* 继承的属性 */

public $is_active ;

public $data ;

public $is_pending ;

public $priority ;

/* 方法 */

public array attr ( void )

public __construct ( string $path , float $interval , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

final public static void createStopped ( string $path , float $interval , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

public void prev ( void )

public void set ( string $path , float $interval )

public bool stat ( void )

/* 继承的方法 */

public int EvWatcher::clear ( void )

abstract public EvWatcher::__construct ( void )

public void EvWatcher::feed ( int $revents )

public EvLoop EvWatcher::getLoop ( void )

public void EvWatcher::invoke ( int $revents )

public bool EvWatcher::keepalive ([ bool $value ] )

public void EvWatcher::setCallback ( callable $callback )

public void EvWatcher::start ( void )

public void EvWatcher::stop ( void )

}

属性

interval
Readonly . Hint on how quickly a change is expected to be detected and should normally be specified as 0.0 to let libev choose a suitable value.

path
Readonly . The path to wait for status changes on.

EvStat::attr

Returns the values most recently detected by Ev

说明

public array EvStat::attr ( void )

Returns array of the values most recently detected by Ev

参数

此函数没有参数。

返回值

Returns array with the values most recently detect by Ev(without actual stat 'ing):

KeyDescription
'dev'ID of device containing file
'ino'inode number
'mode'protection
'nlink'number of hard links
'uid'user ID of owner
'size'total size, in bytes
'gid'group ID of owner
'rdev'device ID (if special file)
'blksize'blocksize for file system I/O
'blocks'number of 512B blocks allocated
'atime'time of last access
'ctime'time of last status change
'mtime'time of last modification

See stat(2) man page for details.

范例

示例 #1 Monitor changes of /var/log/messages

<?php
// Use 10 second update interval.
$w = new EvStat("/var/log/messages", 8, function ($w) {
    echo "/var/log/messages changed\n";

    $attr = $w->attr();

    if ($attr['nlink']) {
        printf("Current size: %ld\n", $attr['size']);
        printf("Current atime: %ld\n", $attr['atime']);
        printf("Current mtime: %ld\n", $attr['mtime']);
    } else {
        fprintf(STDERR, "`messages` file is not there!");
        $w->stop();
    }
});

Ev::run();
?>

参见

  • EvStat::prev
  • EvStat::stat

EvStat::__construct

Constructs EvStat watcher object

说明

public EvStat::__construct ( string $path , float $interval , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

Constructs EvStat watcher object and starts the watcher automatically.

参数

path
The path to wait for status changes on.

interval
Hint on how quickly a change is expected to be detected and should normally be specified as 0.0 to let libev choose a suitable value.

callback
See Watcher callbacks .

data
Custom data associated with the watcher.

priority
Watcher priority

返回值

Returns EvStat watcher object on succes.

范例

示例 #1 Monitor changes of /var/log/messages

<?php
// Use 10 second update interval.
$w = new EvStat("/var/log/messages", 8, function ($w) {
 echo "/var/log/messages changed\n";

 $attr = $w->attr();

 if ($attr['nlink']) {
  printf("Current size: %ld\n", $attr['size']);
  printf("Current atime: %ld\n", $attr['atime']);
  printf("Current mtime: %ld\n", $attr['mtime']);
 } else {
  fprintf(STDERR, "`messages` file is not there!");
  $w->stop();
 }
});

Ev::run();
?>

EvStat::createStopped

Create a stopped EvStat watcher object

说明

final public static void EvStat::createStopped ( string $path , float $interval , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

Creates EvStat watcher object, but doesn't start it automatically(unlike EvStat::__construct ).

参数

path
The path to wait for status changes on.

interval
Hint on how quickly a change is expected to be detected and should normally be specified as 0.0 to let libev choose a suitable value.

callback
See Watcher callbacks .

data
Custom data associated with the watcher.

priority
Watcher priority

返回值

Returns a stopped EvStat watcher object on success.

参见

  • EvStat::__construct
  • EvWatcher::start

EvStat::prev

Returns the previous set of values returned by EvStat::attr

说明

public void EvStat::prev ( void )

Just like EvStat::attr , but returns the previous set of values.

参数

此函数没有参数。

返回值

Returns an array with the same structure as the array returned by EvStat::attr . The array contains previously detected values.

参见

  • EvStat::attr
  • EvStat::stat

EvStat::set

Configures the watcher

说明

public void EvStat::set ( string $path , float $interval )

Configures the watcher.

参数

path
The path to wait for status changes on.

interval
Hint on how quickly a change is expected to be detected and should normally be specified as 0.0 to let libev choose a suitable value.

返回值

没有返回值。

EvStat::stat

Initiates the stat call

说明

public bool EvStat::stat ( void )

Initiates the stat call(updates internal cache). It stats(using lstat ) the path specified in the watcher and sets to the values found.

参数

此函数没有参数。

返回值

Returns TRUE if path exists. Otherwise FALSE.

参见

  • EvStat::attr
  • EvStat::prev

简介

EvTimer watchers are simple relative timers that generate an event after a given time, and optionally repeating in regular intervals after that.

The timers are based on real time, that is, if one registers an event that times out after an hour and resets the system clock to January last year , it will still time out after(roughly) one hour. "Roughly" because detecting time jumps is hard, and some inaccuracies are unavoidable.

The callback is guaranteed to be invoked only after its timeout has passed (not at, so on systems with very low-resolution clocks this might introduce a small delay). If multiple timers become ready during the same loop iteration then the ones with earlier time-out values are invoked before ones of the same priority with later time-out values (but this is no longer true when a callback calls EvLoop::run recursively).

The timer itself will do a best-effort at avoiding drift, that is, if a timer is configured to trigger every 10 seconds, then it will normally trigger at exactly 10 second intervals. If, however, the script cannot keep up with the timer because it takes longer than those 10 seconds to do) the timer will not fire more than once per event loop iteration.

类摘要

EvTimer

class EvTimer extends EvWatcher {

/* 属性 */

public $repeat ;

public $remaining ;

/* 继承的属性 */

public $is_active ;

public $data ;

public $is_pending ;

public $priority ;

/* 方法 */

public void again ( void )

public __construct ( float $after , float $repeat , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

final public static EvTimer createStopped ( float $after , float $repeat , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

public void set ( float $after , float $repeat )

/* 继承的方法 */

public int EvWatcher::clear ( void )

abstract public EvWatcher::__construct ( void )

public void EvWatcher::feed ( int $revents )

public EvLoop EvWatcher::getLoop ( void )

public void EvWatcher::invoke ( int $revents )

public bool EvWatcher::keepalive ([ bool $value ] )

public void EvWatcher::setCallback ( callable $callback )

public void EvWatcher::start ( void )

public void EvWatcher::stop ( void )

}

属性

repeat
If repeat is 0.0 , then it will automatically be stopped once the timeout is reached. If it is positive, then the timer will automatically be configured to trigger again every repeat seconds later, until stopped manually.

remaining
Returns the remaining time until a timer fires. If the timer is active, then this time is relative to the current event loop time, otherwise it's the timeout value currently configured.

That is, after instanciating an EvTimer with an after value of 5.0 and repeat value of 7.0 , remaining returns 5.0 . When the timer is started and one second passes, remaining will return 4.0 . When the timer expires and is restarted, it will return roughly 7.0 (likely slightly less as callback invocation takes some time too), and so on.

EvTimer::again

Restarts the timer watcher

说明

public void EvTimer::again ( void )

This will act as if the timer timed out and restart it again if it is repeating. The exact semantics are:

  1. if the timer is pending, its pending status is cleared.

  2. if the timer is started but non-repeating, stop it (as if it timed out).

  3. if the timer is repeating, either start it if necessary (with the repeat value), or reset the running timer to the repeat value.

参数

此函数没有参数。

返回值

没有返回值。

参见

  • EvWatcher::stop

EvTimer::__construct

Constructs an EvTimer watcher object

说明

public EvTimer::__construct ( float $after , float $repeat , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

Constructs an EvTimer watcher object.

参数

after
Configures the timer to trigger after after seconds.

repeat
If repeat is 0.0 , then it will automatically be stopped once the timeout is reached. If it is positive, then the timer will automatically be configured to trigger again every repeat seconds later, until stopped manually.

callback
See Watcher callbacks .

data
Custom data associated with the watcher.

priority
Watcher priority

返回值

Returns EvTimer object on success.

范例

示例 #1 Simple timers

<?php
// Create and start timer firing after 2 seconds
$w1 = new EvTimer(2, 0, function () {
    echo "2 seconds elapsed\n";
});

// Create and launch timer firing after 2 seconds repeating each second
// until we manually stop it
$w2 = new EvTimer(2, 1, function ($w) {
    echo "is called every second, is launched after 2 seconds\n";
    echo "iteration = ", Ev::iteration(), PHP_EOL;

    // Stop the watcher after 5 iterations
    Ev::iteration() == 5 and $w->stop();
    // Stop the watcher if further calls cause more than 10 iterations
    Ev::iteration() >= 10 and $w->stop();
});

// Create stopped timer. It will be inactive until we start it ourselves
$w_stopped = EvTimer::createStopped(10, 5, function($w) {
    echo "Callback of a timer created as stopped\n";

    // Stop the watcher after 2 iterations
    Ev::iteration() >= 2 and $w->stop();
});

// Loop until Ev::stop() is called or all of watchers stop
Ev::run();

// Start and look if it works
$w_stopped->start();
echo "Run single iteration\n";
Ev::run(Ev::RUN_ONCE);

echo "Restart the second watcher and try to handle the same events, but don't block\n";
$w2->again();
Ev::run(Ev::RUN_NOWAIT);

$w = new EvTimer(10, 0, function() {});
echo "Running a blocking loop\n";
Ev::run();
echo "END\n";
?>

以上例程的输出类似于:

2 seconds elapsed
is called every second, is launched after 2 seconds
iteration = 1
is called every second, is launched after 2 seconds
iteration = 2
is called every second, is launched after 2 seconds
iteration = 3
is called every second, is launched after 2 seconds
iteration = 4
is called every second, is launched after 2 seconds
iteration = 5
Run single iteration
Callback of a timer created as stopped
Restart the second watcher and try to handle the same events, but don't block
Running a blocking loop
is called every second, is launched after 2 seconds
iteration = 8
is called every second, is launched after 2 seconds
iteration = 9
is called every second, is launched after 2 seconds
iteration = 10
END

参见

EvTimer::createStopped

Creates EvTimer stopped watcher object

说明

final public static EvTimer EvTimer::createStopped ( float $after , float $repeat , callable $callback [, mixed $data = NULL [, int $priority = 0 ]] )

Creates EvTimer stopped watcher object. Unlike EvTimer::__construct , this method doesn't start the watcher automatically.

参数

after
Configures the timer to trigger after after seconds.

repeat
If repeat is 0.0 , then it will automatically be stopped once the timeout is reached. If it is positive, then the timer will automatically be configured to trigger again every repeat seconds later, until stopped manually.

callback
See Watcher callbacks .

data
Custom data associated with the watcher.

priority
Watcher priority

返回值

Returns EvTimer watcher object on success.

范例

示例 #1 Monotor changes of /var/log/messages. Avoid missing updates by means of one second delay

<?php
$timer = EvTimer::createStopped(0., 1.02, function ($w) {
    $w->stop();

    $stat = $w->data;

    // 1 second after the most recent change of the file
    printf("Current size: %ld\n", $stat->attr()['size']);
});

$stat = new EvStat("/var/log/messages", 0., function () use ($timer) {
    // Reset timer watcher
    $timer->again();
});

$timer->data = $stat;

Ev::run();
?>

参见

  • EvTimer::__construct
  • EvPeriodic

EvTimer::set

Configures the watcher

说明

public void EvTimer::set ( float $after , float $repeat )

Configures the watcher

参数

after
Configures the timer to trigger after after seconds.

repeat
If repeat is 0.0 , then it will automatically be stopped once the timeout is reached. If it is positive, then the timer will automatically be configured to trigger again every repeat seconds later, until stopped manually.

返回值

没有返回值。

简介

EvWatcher is a base class for all watchers( EvCheck , EvChild etc.). Since EvWatcher 's constructor is abstract , one can't(and don't need to) create EvWatcher objects directly.

类摘要

EvWatcher

abstract class EvWatcher {

/* 属性 */

public $is_active ;

public $data ;

public $is_pending ;

public $priority ;

/* 方法 */

public int clear ( void )

abstract public __construct ( void )

public void feed ( int $revents )

public EvLoop getLoop ( void )

public void invoke ( int $revents )

public bool keepalive ([ bool $value ] )

public void setCallback ( callable $callback )

public void start ( void )

public void stop ( void )

}

属性

is_active
Readonly . TRUE if the watcher is active. FALSE otherwise.

data
User custom data associated with the watcher

is_pending
Readonly .TRUE if the watcher is pending, i.e. it has outstanding events, but its callback has not yet been invoked. FALSE otherwise. As long, as a watcher is pending(but not active), one must not change its priority.

priority
Integer between Ev::MINPRI and Ev::MAXPRI . Pending watchers with higher priority will be invoked before watchers with lower priority, but priority will not keep watchers from being executed(except for EvIdle watchers). EvIdle watchers provide functionality to suppress invocation when higher priority events are pending.

EvWatcher::clear

Clear watcher pending status

说明

public int EvWatcher::clear ( void )

If the watcher is pending, this method clears its pending status and returns its revents bitset(as if its callback was invoked). If the watcher isn't pending it does nothing and returns 0 .

Sometimes it can be useful to "poll" a watcher instead of waiting for its callback to be invoked, which can be accomplished with this function.

参数

此函数没有参数。

返回值

In case if the watcher is pending, returns revents bitset as if the watcher callback had been invoked. Otherwise returns 0 .

EvWatcher::__construct

Abstract constructor of a watcher object

说明

abstract public EvWatcher::__construct ( void )

EvWatcher::__construct is an abstract constructor of a watcher object implemented in the derived classes.

EvWatcher::feed

Feeds the given revents set into the event loop

说明

public void EvWatcher::feed ( int $revents )

Feeds the given revents set into the event loop, as if the specified event had happened for the watcher.

参数

revents
Bit mask of watcher received events .

返回值

没有返回值。

EvWatcher::getLoop

Returns the loop responsible for the watcher

说明

public EvLoop EvWatcher::getLoop ( void )

Returns the loop responsible for the watcher

参数

此函数没有参数。

返回值

Returns EvLoop event loop object responsible for the watcher.

EvWatcher::invoke

Invokes the watcher callback with the given received events bit mask

说明

public void EvWatcher::invoke ( int $revents )

Invokes the watcher callback with the given received events bit mask.

参数

revents
Bit mask of watcher received events .

返回值

没有返回值。

EvWatcher::keepalive

Configures whether to keep the loop from returning

说明

public bool EvWatcher::keepalive ([ bool $value ] )

Configures whether to keep the loop from returning. With keepalive value set to FALSE the watcher won't keep Ev::run / EvLoop::run from returning even though the watcher is active.

Watchers have keepalive value TRUE by default.

Clearing keepalive status is useful when returning from Ev::run / EvLoop::run just because of the watcher is undesirable. It could be a long running UDP socket watcher or so.

参数

value
With keepalive value set to FALSE the watcher won't keep Ev::run / EvLoop::run from returning even though the watcher is active.

返回值

Returns the previous state.

范例

示例 #1 Register an I/O watcher for some UDP socket but do not keep the event loop from running just because of that watcher.

<?php
$udp_socket = ...
$udp_watcher = new EvIo($udp_socket, Ev::READ, function () { /* ... */ });
$udp_watcher->keepalive(FALSE);
?>

EvWatcher::setCallback

Sets new callback for the watcher

说明

public void EvWatcher::setCallback ( callable $callback )

Sets new callback for the watcher

参数

callback
See Watcher callbacks .

返回值

没有返回值。

EvWatcher::start

Starts the watcher

说明

public void EvWatcher::start ( void )

Marks the watcher as active. Note that only active watchers will receive events.

参数

此函数没有参数。

返回值

没有返回值。

参见

  • EvWatcher::stop

EvWatcher::stop

Stops the watcher

说明

public void EvWatcher::stop ( void )

Marks the watcher as inactive. Note that only active watchers will receive events.

参数

此函数没有参数。

返回值

没有返回值。

参见

  • EvWatcher::start