大网数据广告活动
PHP 语言与运行手册

The EventBase class

· 52CE 我爱测

EventBase class represents libevent's event base structure. It holds a set of events and can poll to determine which events are active.

The EventBase class

(PECL event >= 1.2.6-beta)

Introduction

EventBase class represents libevent's event base structure. It holds a set of events and can poll to determine which events are active.

Each event base has a method, or a backend that it uses to determine which events are ready. The recognized methods are: select, poll, epoll, kqueue, devpoll, evport and win32.

To configure event base to use, or avoid specific backend EventConfig class can be used.

Warning

Do NOT destroy the EventBase object as long as resources of the associated Event objects are not released. Otherwise, it will lead to unpredictable results!

Class synopsis

final class EventBase {
/* Constants */
const int LOOP_ONCE = 1;
const int LOOP_NONBLOCK = 2;
const int NOLOCK = 1;
const int STARTUP_IOCP = 4;
const int NO_CACHE_TIME = 8;
/* Methods */
public function __construct( EventConfig $cfg = ?)
public function dispatch(): void
public function exit( float $timeout = ?): bool
public function free(): void
public function getFeatures(): int
public function getMethod(): string
public function getTimeOfDayCached(): float
public function gotExit(): bool
public function gotStop(): bool
public function loop( int $flags = ?): bool
public function priorityInit( int $n_priorities ): bool
public function reInit(): bool
public function stop(): bool
}

Predefined Constants

EventBase::LOOP_ONCE

Flag used with EventBase::loop() method which means: "block until libevent has an active event, then exit once all active events have had their callbacks run".

EventBase::LOOP_NONBLOCK

Flag used with EventBase::loop() method which means: "do not block: see which events are ready now, run the callbacks of the highest-priority ones, then exit".

EventBase::NOLOCK

Configuration flag. Do not allocate a lock for the event base, even if we have locking set up".

EventBase::STARTUP_IOCP

Windows-only configuration flag. Enables the IOCP dispatcher at startup.

EventBase::NO_CACHE_TIME

Configuration flag. Instead of checking the current time every time the event loop is ready to run timeout callbacks, check after each timeout callback.

EventBase::EPOLL_USE_CHANGELIST

If we are using the epoll backend, this flag says that it is safe to use Libevent's internal change-list code to batch up adds and deletes in order to try to do as few syscalls as possible.

Setting this flag can make code run faster, but it may trigger a Linux bug: it is not safe to use this flag if one has any fds cloned by dup(), or its variants. Doing so will produce strange and hard-to-diagnose bugs.

This flag can also be activated by setting the EVENT_EPOLL_USE_CHANGELIST environment variable.

This flag has no effect if one winds up using a backend other than epoll.

Table of Contents

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。