In the case if pcntl_sigtimedwait() is unavailable (under Mac OS, under PHP < 5.3), you can pick up the workaround:
<?php
if (!function_exists('pcntl_sigtimedwait'))
{
function pcntl_sigtimedwait($signals,$siginfo,$sec,$nano)
{
pcntl_signal_dispatch();
if (time_nanosleep($sec,$nano) === TRUE) {return FALSE;}
pcntl_signal_dispatch();
return TRUE;
}
}
?>
Behaviour of this function differs from original one. This function returns true if a signal was retrieved and false if it was not retrieved. However, the timeout will be interrupted immediately when signal sent.
pcntl_sigtimedwait
(PHP 5 >= 5.3.0)
pcntl_sigtimedwait — 带超时机制的信号等待
说明
int pcntl_sigtimedwait
( array
$set
[, array &$siginfo
[, int $seconds = 0
[, int $nanoseconds = 0
]]] )
函数pcntl_sigtimedwait()实际上与pcntl_sigwaitinfo()
的行为一致,不同在于它多了两个增强参数seconds和
nanoseconds,这使得脚本等待的事件有了一个时间的上限。
参数
-
set -
要等待的信号列表数组。
-
siginfo -
siginfo是一个输出参数,用来返回信号的信息。更详细情况参见 pcntl_sigwaitinfo()。 -
seconds -
超时秒数。
-
nanoseconds -
超时纳秒数。
返回值
成功时,函数pcntl_sigtimedwait()返回信号编号。
kak dot serpom dot po dot yaitsam at gmail dot com
26-Jul-2009 09:50
