加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP运行非阻塞系统调用

发布时间:2020-12-13 17:08:39 所属栏目:PHP教程 来源:网络整理
导读:如何在 PHP中运行非阻塞系统调用? 系统调用将调用由第二个PHP脚本运行的流服务..所以我的页面坐下来等待这个调用. 我对解决方案的两点看法: 1:存在通过非阻塞执行系统调用的本机方法/参数 2:在一个新的C程序上运行system(),然后在一个sep上自行分叉并运
如何在 PHP中运行非阻塞系统调用?

系统调用将调用由第二个PHP脚本运行的流服务..所以我的页面坐下来等待这个调用.

我对解决方案的两点看法:

1:存在通过非阻塞执行系统调用的本机方法/参数

2:在一个新的C程序上运行system(),然后在一个sep上自行分叉并运行实际的php脚本.线

是否存在以非阻塞方式执行系统调用的本机方法,或者我是否需要破解此问题…

我目前有shell_exec(‘nohup php /path/to/file.php&’)但它仍然有效

解决方法

从 PHP manual开始:

If a program is started with this function,in order for it to
continue running in the background,the output of the program must be
redirected to a file or another output stream. Failing to do so will
cause PHP to hang until the execution of the program ends.

在同一页面上的注释中提供了一个示例(基于Linux):

If you want to start a php process that continues to run independently
from apache (with a different parent pid) use nohub. Example:

exec(‘nohup php process.php > process.out 2> process.err < /dev/null &’);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读