且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

shell_exec()超时管理和exec()

更新时间:2022-02-21 01:48:07

我建议您考虑使用proc_open.您可以配置它以返回流资源,手动保留一个计时器,如果计时器在处理完成之前到期,则可以使用proc_terminate终止它.如果确实在计时器到期之前完成,则可以使用proc_close然后使用stream_get_contents来抓取本来应该写入stdout的数据.

I would suggest you look into using proc_open. You can configure it to return a stream resource, manually keep a timer, and if the timer expires before the process completes, you can terminate it with proc_terminate. If it does complete before the timer expires, then you can use proc_close then stream_get_contents to grab the data that would have otherwise been written to stdout.

请参见 http://www.php.net/manual/zh/function.proc-open.php