且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在挂起的PHP页面上后台运行进程

更新时间:2023-02-22 21:07:05

Nohup似乎无法解决问题,因为它仍重定向到stdout.我在我的linux dev框中确认了.

Nohup doesn't seem to fix the problem because it still redirects to stdout. I confirmed on my linux dev box.

您需要做的是将输出重定向到stdout/stderr之外:

What you need to do is redirect the output away from stdout/stderr:

shell_exec("sudo python /home/pi/Desktop/PiControl/motion_sensor.py >/dev/null 2>&1 &");

通过添加>/dev/null,您会将输出定向到/dev/null.通过使用2>&1,您可以将错误引导到与输出(/dev/null)相同的位置.如果需要,您也可以使用日志文件.如果要附加到文件,请将>更改为>>.

By adding >/dev/null you are directing the output to /dev/null. By using 2>&1 you are directing the errors to the same place as the output (/dev/null). You could also use a log file if you want. If you want to append to the file, change > to >>.