问题描述
我已经得到了需要调用一个shell脚本,但根本不关心产出的PHP脚本。 shell脚本使得一些SOAP调用,并缓慢完成,所以我不想在等待答复减慢PHP请求。事实上,PHP请求应该能退出而不终止shell进程。
I've got a PHP script that needs to invoke a shell script but doesn't care at all about the output. The shell script makes a number of SOAP calls and is slow to complete, so I don't want to slow down the PHP request while it waits for a reply. In fact, the PHP request should be able to exit without terminating the shell process.
我已经研究过各种执行exec()
,了shell_exec()
, pcntl_fork()
等功能,但他们都不提供我想要的东西。 (或者,如果他们这样做,这不是我清楚如何。)有什么建议?
I've looked into the various exec()
, shell_exec()
, pcntl_fork()
, etc. functions, but none of them seem to offer exactly what I want. (Or, if they do, it's not clear to me how.) Any suggestions?
推荐答案
如果它不关心产出,不能在EXEC的脚本与&放大器被称为/ code>来后台进程?
If it "doesn't care about the output", couldn't the exec to the script be called with the
&
to background the process?
修改 - 纳入什么@ 评论这个职位,你可以将它添加到到
EXEC通话
:
EDIT - incorporating what @AdamTheHut commented to this post, you can add this to a call to
exec
:
" > /dev/null 2>/dev/null &"
这将重定向既
STDIO
(第>
)和标准错误
( 2 - ;
)为的/ dev / null的
,并在后台运行
That will redirect both
stdio
(first >
) and stderr
(2>
) to /dev/null
and run in the background.
有其他方法可以做到同样的事情,但是这是最简单的阅读。
There are other ways to do the same thing, but this is the simplest to read.
以上双重定向的替代:
" &> /dev/null &"
这篇关于在PHP中的异步壳EXEC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!