PHP exec 命令阻止 echo 工作
PHP exec command prevents echo from working
在此代码中:
session_write_close();
echo "reload";
flush();
// exec("/etc/init.d/streaminit stop");
// sleep(2);
// session_write_close();
// exec("/etc/init.d/streaminit start");
// //all we have to do is copy currentView into nextView to trigger a page reload
// sleep(2);
"reload" 的回显有效,但如果它下面的行未注释,则不会回显任何内容。我已经尝试了很多排列组合,结论是 exec
命令阻止了 echo
工作。
我发现一些关于 exec
导致 Apache2 出现问题的讨论,并且有人说 session_write_close()
可能会阻止该问题。显然在这种情况下它没有。是否有任何已知的修复方法?难道我做错了什么?
(streaminit
是一个启动和停止 mjpeg_streamer
的 shell 脚本。shell 命令是异步的(最后是 &
) )
我终于在 PHP 的 exec
的文档中找到了这个:"If a program is started with this function, in order for it to continue running in the background (my emphasis), 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." 修复:
exec("/etc/init.d/streaminit stop > /dev/null 2>&1 &”);
对于那些不熟悉的人(就像我直到一分钟前),这会将 stdout
设备重定向到 /dev/null
,而 2>&1
表示 "send stderr
output to the same place as stdout
. Finally, the &
means "运行 此命令在后台运行。有效!
在此代码中:
session_write_close();
echo "reload";
flush();
// exec("/etc/init.d/streaminit stop");
// sleep(2);
// session_write_close();
// exec("/etc/init.d/streaminit start");
// //all we have to do is copy currentView into nextView to trigger a page reload
// sleep(2);
"reload" 的回显有效,但如果它下面的行未注释,则不会回显任何内容。我已经尝试了很多排列组合,结论是 exec
命令阻止了 echo
工作。
我发现一些关于 exec
导致 Apache2 出现问题的讨论,并且有人说 session_write_close()
可能会阻止该问题。显然在这种情况下它没有。是否有任何已知的修复方法?难道我做错了什么?
(streaminit
是一个启动和停止 mjpeg_streamer
的 shell 脚本。shell 命令是异步的(最后是 &
) )
我终于在 PHP 的 exec
的文档中找到了这个:"If a program is started with this function, in order for it to continue running in the background (my emphasis), 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." 修复:
exec("/etc/init.d/streaminit stop > /dev/null 2>&1 &”);
对于那些不熟悉的人(就像我直到一分钟前),这会将 stdout
设备重定向到 /dev/null
,而 2>&1
表示 "send stderr
output to the same place as stdout
. Finally, the &
means "运行 此命令在后台运行。有效!