永远循环
<?php $timeouts = 10000000; //callback function function func($fd, $event,$arg) { $time = time(); for($i=0;$i<2;$i++) { echo "Timer-$arg: $time : out-$i\n"; sleep(3); } } //create base and event $base = event_base_new(); for($i=0;$i<2;$i++) { $event[$i] = event_new(); //set event flags event_set($event[$i], $i , EV_PERSIST, 'func', "$i"); //set event base event_base_set($event[$i], $base); //enable event event_add($event[$i], $timeouts); } //start event loop event_base_loop($base);
运行一次然后退出
event_base_loop($base, EVLOOP_ONCE );
<?php $timeouts = 10; //callback function function func($fd, $event,$arg) { $time = time(); echo "Timer-$arg: $time\n"; } //create base and event $base = event_base_new(); for($i=0;$i<10;$i++) { $event[$i] = event_new(); //set event flags event_set($event[$i], $i , EV_PERSIST, 'func', "$i"); //set event base event_base_set($event[$i], $base); //enable event event_add($event[$i], $timeouts); } //start event loop event_base_loop($base, EVLOOP_ONCE ); event_base_loop($base, EVLOOP_ONCE ); event_base_loop($base, EVLOOP_ONCE ); event_base_loop($base, EVLOOP_ONCE );
原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。