php shell_exec 在后台一次执行多个命令
我在 php/linux 中遇到问题,如下所述:
我必须通过 shell_exec (plesk cli 命令订阅 webspace-off)执行 linux 命令。
问题是,当我从 php 执行此操作时,它可以工作,但是重新启动 apache,导致在 apache 重新启动时出现空白页面。
为了解决这个问题,我必须在后台调用 shell_exec,并延迟(预期结果:网页加载,4 秒后运行 Linux 脚本。)
我已经做了一些尝试,例如:
shell_exec("sleep 4 && /var/www/vhosts/site.com/httpdocs/wrapper2 3 --webspace-off ".$domain_name." &");
但是 php 会等待回复。
不知怎的,我需要休眠一个linux命令的执行,而所有这些都必须在bg中运行。, 并且不要等待回复。
谢谢
I have a problem in php/linux, described below:
I have to execute a linux command through shell_exec (plesk cli command subscription webspace-off).
The problem is when i do this from php it works, but restarts apache, that resulting in a blank page, while apache restarts.
To get rid of the problem i have to call that shell_exec in background, with a delay (Expected result: the web page loads, and after 4 sec. runs the linux script.)
I have done some tryings like:
shell_exec("sleep 4 && /var/www/vhosts/site.com/httpdocs/wrapper2 3 --webspace-off ".$domain_name." &");
but php will wait for response.
Somehow i need to sleep the execution of a linux command , and all this has to run in bg.,
and dont wait for response.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该尝试使用
exec
而不是 < code>shell_exec,并将所有输出重定向到/dev/null
。像这样的东西:(注意命令周围的
()
:您需要捕获sleep
和包装器的输出流。)编辑:并使 real< /strong> 确保您验证
$domain_name
。如果没有验证,你就有麻烦了......
You should try using
exec
rather thanshell_exec
, and redirect all output to/dev/null
. Something like:(Note the
()
around the commands: you need to catch the output stream of bothsleep
and your wrapper.)Edit: and make real sure that you validate
$domain_name
. Without validation and withyou're in trouble...