Windows 和 Linux 上的 exec() 参数 /dev/null 和 & 符号?
来自 exec()
手册页:
如果一个程序用这个函数启动,为了让它 继续在后台运行,程序的输出必须是 重定向到文件或另一个输出流。如果不这样做将会 导致 PHP 挂起,直到程序执行结束。
所以,看来我应该重定向输出到某个东西,并在Linux下添加与号,以使我的脚本真正在后台运行。
我应该如何“翻译” Windows 的 /dev/null
和 &
?任何机会使用 php://
来制作操作系统安全吗?
exec('php ' . __DIR__ . '/script.php > /dev/null &');
From exec()
manual page:
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.
So, it seems i should redirect output to something and add ampersand under Linux, to make my script truly running in background.
How i'm supposed to "translate" /dev/null
and &
for Windows? Any chance to use php://
to make it OS safe?
exec('php ' . __DIR__ . '/script.php > /dev/null &');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)