pcntl_signal_dispatch
序列,或者像libev扩展一样,我必须使用run
方法来阻止进程等待信号回调。但是在C语言中什么也没有,并且信号处理程序可以自动触发。是否有设计目的?或者不能在php中实现。
尤其是我不想破坏其原始项目结构。 如:
// no willing that
function tool_started_callback(){
set_tool_timer(2,function(){log()});
normal_business_ahead();
}
start_tool("tool_started_callback"); // blocking.
// willing that
tool_init();
business_step1();
tool_timer(2,function(){log()}); // the arg2 is a read only function.
business_step2();
while(1){
// it means a long time task. And also means user using the tool will not
// ACTIVLEY check whether the timer signal is arriving and handle it.
do_something();
// signal may interrupt anywhen like C.
}
那么,除了declare($ticks)
之外,还有其他方法吗?例如后台任务?线程?