ev.php,pecl-ev

软件简介

ev是一个php的事件拓展,通过PECL进行安装,以libev

library为接口,是一个用C语言编写的事件循环类库,所以ev是一个高效的事件拓展。同时可通过ev让php进行异步操作。

目前仅对GNU / Linux平台提供支持,今后可能会对其他平台提供支持。

采用的是PHP协议。

范例

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值