为接口,是一个用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 stoppedn"; // Stop the watcher after 2 iterations Ev::iteration() >= 2 and $w->stop();});// Loop until Ev::stop() is called or all of watchers stopEv::run();// Start and look if it works$w_stopped->start();echo "Run single iterationn";Ev::run(Ev::RUN_ONCE);echo "Restart the second watcher and try to handle the same events, but don't blockn";$w2->again();Ev::run(Ev::RUN_NOWAIT);$w = new EvTimer(10, 0, function() {});echo "Running a blocking loopn";Ev::run();echo "ENDn";?>
输出
2 seconds elapsedis called every second, is launched after 2 secondsiteration = 1is called every second, is launched after 2 secondsiteration = 2is called every second, is launched after 2 secondsiteration = 3is called every second, is launched after 2 secondsiteration = 4is called every second, is launched after 2 secondsiteration = 5Run single iterationCallback of a timer created as stoppedRestart the second watcher and try to handle the same events, but don't blockRunning a blocking loopis called every second, is launched after 2 secondsiteration = 8is called every second, is launched after 2 secondsiteration = 9is called every second, is launched after 2 secondsiteration = 10END