为什么在EXEC PHP中运行NOHUP时,为什么要更新NOHUP.OUT

发布于 2025-01-19 01:08:57 字数 347 浏览 3 评论 0原文

我正在运行PHP插座。我通过NOHUP运行该程序。通过根正确运行此程序。但是我的问题是通过php中的exec()函数运行程序。当我以这种方式运行命令时,程序可以正确运行,但程序输出未在NOHUP.OUT中打印。

我在SSH中的命令: nohup php my_path/example.php&

在用户php中工作我的命令: exec('nohup php my_path/example.php>/dev/null 2>&&'',$ output); #not Update nohup.out

请指导我...

I'm running a php socket. I run the program through nohup. Run this program properly through root. But my problem is running the program via the exec () function in php. When I run the command this way the program runs correctly but the program output is not printed in nohup.out.

my command in ssh:
nohup php my_path/example.php & #is working

my command in user php:
exec('nohup php my_path/example.php >/dev/null 2>&1 &', $output); #not update nohup.out

please guide me...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离笑几人歌 2025-01-26 01:08:57

来自 exec 上的 PHP 文档:

如果程序使用此函数启动,为了使其继续在后台运行,程序的输出必须重定向到文件或另一个输出流。如果不这样做将导致 PHP 挂起,直到程序执行结束。

来自 man nohup

如果标准输入是终端,则从 /dev/null 重定向它。如果标准输出是终端,则尽可能将输出附加到“nohup.out”,否则附加到“$HOME/nohup.out”。如果标准错误是终端,则将其重定向到标准输出。要将输出保存到文件,请使用“nohup COMMAND >”文件'。

为了满足两者 - 手动重定向到 nohup.out

exec('nohup php my_path/example.php >>nohup.out 2>&1 &', $output);

From PHP docs on exec:

If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.

From man nohup:

If standard input is a terminal, redirect it from /dev/null. If standard output is a terminal, append output to 'nohup.out' if possible, '$HOME/nohup.out' otherwise. If standard error is a terminal, redirect it to standard output. To save output to FILE, use 'nohup COMMAND > FILE'.

To satisfy both - redirect manually to nohup.out:

exec('nohup php my_path/example.php >>nohup.out 2>&1 &', $output);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文