有没有办法以比 pcntl_alarm(int $seconds) 更细粒度的延迟来发出 SIGALRM 信号?
pcntl_alarm(int $seconds)
仅具有秒的分辨率。 PHP 有没有办法以延迟(例如,毫秒)发出 SIGALRM 信号?也许是带有延迟参数的 posix_kill() ?
PS.:我知道 PECL 扩展 Swoole 中的 Swoole\Process::alarm()
,但我正在寻找更简单的 PHP 解决方案。
pcntl_alarm(int $seconds)
only has a resolution of seconds. Is there a way in PHP to signal a SIGALRM with a delay of, say, milliseconds? Maybe a posix_kill()
with a delay argument?
PS.: I'm aware of Swoole\Process::alarm()
from the PECL extension Swoole, but I'm looking for a more bare-bones PHP solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一种方法来做到这一点,但它有点复杂:
......而且它太消耗资源了。而且因为它每次都需要生成一个新进程,时间可能也不是很准确。
附录:
我设法通过仅创建一个长时间运行的中断程序进程而不是为每个中断请求创建短期运行的进程来提高其效率。
它距离理想还很远,但目前已经完成了工作:
I found one way to do it, but it is a bit convoluted:
...and it's way too resource intensive. And because it needs to spawn a new process each time probably not very time-accurate either.
Addendum:
I've managed to make it more efficient by creating only one long-running interrupter process, instead of creating short-running processes for each interruption request.
It's still far from ideal, but it does the job for now: