【发布时间】:2014-06-24 10:28:57
【问题描述】:
我正在使用以下方式运行我的 cron:
$command = 'wget -qO- --timeout=0 --tries=1 my_url &';
$descriptorspec = array(
0 = > array('pipe', 'w'), // stdin
1 = > array('pipe', 'w'), // stdout
2 = > array('pipe', 'w') // stderr
);
$proc = proc_open($command, $descriptorspec, $pipes);
proc_close($proc);
我必须使用 timeout=0 的原因是 cron 运行的时间范围从几秒到几小时不等。但是我注意到如果 cron 花费的时间超过几分钟,如果我以上述方式运行它,它会一直挂在进程树中(即使工作完成,所以 cron 完成了它的任务)。我试图通过发送来强制它停止:
header("Connection: close");
ob_end_flush();
ob_flush();
flush();
我想要实现的是能够准确地知道进程何时完成,这样我就可以确定它停止是因为它成功了还是因为出现了某种错误。
每个 cron 看起来都类似于:
session_write_close();
ignore_user_abort(1);
.... do_the_job ....
header("Connection: close");
ob_end_flush();
ob_flush();
flush();
exit();
如何强制 wget 死掉?我将不胜感激在这件事上的任何提示。我也试过 curl 没有运气。
【问题讨论】: