【发布时间】:2016-01-28 20:58:23
【问题描述】:
我正在使用proc_open() 创建一个后台进程,并且想知道如何在我的后台进程仍在运行时从不同的文件或操作取消或停止此后台进程?
这是我的代码:
$errorLog = './error.log';
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", $errorLog, "a") // stderr is a file to write to
);
proc_open("/var/bin/php /home/hello/myscript.php &", $descriptorspec, $pipes);
我已经阅读了有关proc_terminate($process) 的信息,但似乎需要proc_open() 返回的内容才能停止该过程。在同一个脚本中没有proc_open() 的情况下,有什么办法可以阻止它?
【问题讨论】:
-
您可以尝试将 proc_open 中的 PID 写入文件,然后让辅助脚本检查该文件是否存在,获取 PID,然后尝试终止它。
-
是的,不要使用
proc_terminate(),而是使用posix_kill()或类似的东西。