为什么在PHP中使用的系统信号必须通过pcntl_signal_dispatch之类的某些功能进行设置?

时间:2018-07-24 17:41:45

标签: php

  1. 为什么在PHP中,当我想使用诸如pcntl的信号时,有必要的pcntl_signal_dispatch序列,或者像libev扩展一样,我必须使用run方法来阻止进程等待信号回调。

但是在C语言中什么也没有,并且信号处理程序可以自动触发。是否有设计目的?或者不能在php中实现。

  1. 我将设计一个php工具来监视全局变量并设置一个计时器来记录它们在fpm和cli sapi中。但是我不太愿意使该工具与使用它的项目高度结合。

尤其是我不想破坏其原始项目结构。 如:

// 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)之外,还有其他方法吗?例如后台任务?线程?

0 个答案:

没有答案