chh/eventor
Composer 安装命令:
composer require chh/eventor
包简介
A sane interface to PHP's libevent extension.
关键字:
README 文档
README
A sane interface to PHP's libevent Extension
Install
Install it via composer:
{
"require": {
"chh/eventor": "*"
}
}
Then do:
# Only if you don't have composer:
% wget http://getcomposer.org/composer.phar
% php composer.phar install
Example
<?php
$base = new Eventor\Base;
$fd = STDIN;
# Call the callback every time data is
# written to $fd.
$event = $base->read($fd, function($event) {
static $requests = 0;
$requests++;
if ($requests == 10) {
$event->base->exit();
}
printf("You wrote: %s", fgets($event->fd));
});
$base->loop();
API
class Eventor
Methods
Eventor\Event read(resource $fd, callable $callback)
Creates a new read event and registers it in the event loop with the
given $callback.
When data is written to $fd the callback is called and receives an instance of Eventor\Event as sole argument.
Eventor\Event write(resource $fd, callable $callback)
Creates a new write event and registers it in the event loop with the
given $callback.
When data can be written to $fd the callback is called and receives an instance of
Eventor\Event as sole argument.
add(Eventor\Event $event)
Register a manually created Event instance in the event loop.
delete(Eventor\Event $event)
Delete the event from the event loop, which causes it to trigger the callback never again.
loop()
Starts the event loop, this blocks until all events are dispatched (if the events
are not persistent) or one of the breakLoop() or exit() methods is called
on the Eventor\Base.
halt()
Breaks the loop immediately, similar to using the break keyword in a loop.
shutdown(int $timeout = -1)
Gracefully shut down the event loop by finishing the next dispatch and
exiting after the timeout. The $timeout argument receives the time in
microseconds when the loop should exit, when omitted the loop is exited after
the next dispatch.
class Eventor\Event
The Event class is useful for more low level access to the libevent extensions'
functionality and is also passed to the event handlers when they're called.
Methods
__construct(resource $fd, int $events, callable $callback)
Initializes the event instance with the file descriptor and the
flags. Events is an integer consisting of one or more of these constants
defined in the Eventor\Event class:
Event::READ, listens on writes to the file descriptor.Event::WRITEEvent::SIGNAL, the file descriptor is handled as signal.Event::TIMEOUT, triggers the event after a timeout.Event::PERSIST, event is not deleted from the base after the handler was called. This is set by default, you have to callsetNonPersistent()to disable this flag.
Example:
<?php
use Eventor\Event,
Eventor\Base;
$base = new Base;
$event = new Event(STDIN, Event::READ, function($event) {
echo fgets($event->fd);
});
$base->add($event);
$base->loop();
setNonPersistent($enable = true)
Sets the event to non-persistent mode, by registering it without setting
the Eventor\Event::PERSIST flag. This causes the event handler to get triggered only once.
Properties
base
The instance of the Eventor\Base, to which this event is bound. Is null in the case this event is not bound to any base.
callback
The callback which gets called when the event is ready.
fd
The fd property is the file descriptor, to which this event is bound.
License
Copyright © 2012 Christoph Hochstrasser
Eventor is licensed under the MIT license which is bundled with this
package in the file LICENSE.txt.
chh/eventor 适用场景与选型建议
chh/eventor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 3, 最近一次更新时间为 2012 年 03 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「libevent」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 chh/eventor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 chh/eventor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 chh/eventor 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Kraken Framework Loop Component.
simple php websocket server with examples and demo: simple chat (single daemon) - http://sharoid.ru/chat.html , pro chat (master + worker) - http://sharoid.ru/chat2.html , simple game - http://sharoid.ru/game.html
simple php websocket server with examples and demo: simple chat (single daemon) - http://sharoid.ru/chat.html , pro chat (master + worker) - http://sharoid.ru/chat2.html , simple game - http://sharoid.ru/game.html
Dazzle Asynchronous I/O Event Loop.
examples for simple php websocket server: simple chat (single daemon) - http://sharoid.ru/chat.html , pro chat (master + worker) - http://sharoid.ru/chat2.html , simple game - http://sharoid.ru/game.html
Event loops for event-driven/async PHP
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2012-03-23