使用exec函数的php后台进程 [英] php background process using exec function

查看:255
本文介绍了使用exec函数的php后台进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我进行了很多搜索,找到了确切的答案,但没有找到答案.

I have searched a lot to find the exact answer but didn't find any.

许多人提到我们应该在命令结束时& 不要等待响应.
例如在后台运行 bg.php ,建议:

many people mentioned that we should & at end of command to don't wait for response.
for example to run bg.php in background , this was recommended:

exec("/usr/bin/php bg.php &");  

但这对我不起作用.并且主脚本等待 bg.php 的完全执行.

but it doesn't work for me. and the main script waits for complete execution of the bg.php.

我还读了一些地方,在日志文件中写入了 bg.php 输出,但是我的后台脚本没有产生任何输出.它执行一些过程,然后在数据库中写一些东西.

I also read somewhere to write bg.php output in a logfile but my background script doesn't produce any output. It does some process and then write something in database.

我只希望我的脚本运行bg.php,而不必等待它结束.

请帮助我提供正确的代码.

please help me including correct code.

推荐答案

您也必须将程序输出重新路由到某个地方,通常是/dev/null

You have to reroute programs output somewhere too, usually /dev/null

exec($cmd . " > /dev/null &");

这篇关于使用exec函数的php后台进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆