简体   繁体   English

如何在后台从php执行shell命令

[英]How to execute shell command from php in background

How can I execute shell command in background using & at the end? 如何在后台使用&执行shell命令? I've try: 我试过了:

php -r "shell_exec('sleep 10 &');"

and

php -r "shell_exec('/bin/bash -c \"sleep 10 &\"');"

in both cases it pause for 10 seconds instead of just give the shell back and run sleep in background. 在这两种情况下,它都会暂停10秒,而不是仅仅返回shell并在后台运行睡眠。

You have to reroute the output somewhere. 你必须在某处重新路由输出。 Try something like this: 尝试这样的事情:

php -r "shell_exec('sleep 10 > /dev/null &');"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM