The Swoole\Event class
(PECL swoole >= 1.9.0)
Introduction
The Swoole extension provides low-level interfaces to directly manipulate the underlying epoll/kqueue/poll/select event loop. It allows adding sockets created by other extensions or PHP's stream/socket extensions to Swoole's EventLoop.
Note:
The Event module is low-level, being a basic encapsulation of epoll. Users should have experience with IO multiplexing programming.
Event Priority
Signal handler callback functions set via Process::signal
Timer callback functions set via Timer::tick and Timer::after
Deferred execution functions set via Event::defer
Periodic callback functions set via Event::cycle
Swoole Event Socket Type
fd
int
File descriptors, including Swoole\Client->$sock, Swoole\Process->$pipe, or any other file descriptor (fd).
stream resource
resource
Resources created by stream_socket_client/fsockopen.
socket resource
resource
Resources created by socket_create from the sockets extension require the --enable-sockets flag during Swoole compilation.
object
object
Swoole automatically converts Swoole\Process into UnixSocket and Swoole\Client into connected client sockets at the underlying level.
Class synopsis
mixed
$sock,callable
$read_callback,callable
$write_callback = ?,int
$flags = ?): bool
$fd, int $events
=
SWOOLE_EVENT_READ | SWOOLE_EVENT_WRITE
): boolTable of Contents
- Swoole\Event::add — Add a socket to the underlying reactor event listener
- Swoole\Event::cycle — Define a function to execute at the end of each event loop iteration
- Swoole\Event::defer — Execute a function at the start of the next event loop
- Swoole\Event::del — Remove a socket from reactor event listener
- Swoole\Event::dispatch — Perform a single event loop iteration
- Swoole\Event::isset — Check if a socket is being monitored in the event loop
- Swoole\Event::set — Modify event listener callbacks and mask
- Swoole\Event::wait — Start event loop
- Swoole\Event::write — Write data to socket asynchronously
来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。
