我有一个bash脚本,它有几行代码,如下所示
echo "Do something"
/bin/sh -c 'echo $$>pidfile && exec "command"' &
echo "Ran Command">/path/to/outputfile.txt
exit 0然后我从PHP脚本中调用它
return shell_exec("/path/to/bash/script arguments");
现在,当我这样做时,该命令将成功运行,outputfile.txt包含"Ran“。
但是,PHP脚本在10秒后超时。 bash脚本运行大约需要2-3秒。
如果我将行改为return shell_exec("/path/to/bash/script arguments >/dev/null 2>&1");
然后执行它,PHP脚本不会超时。
我理解为什么重定向输出让PHP继续执行,但我不明白为什么PHP一开始就需要超时。有人能帮我个忙吗?
发布于 2016-09-02 15:34:05
测试这两个版本,您就可以得到它:
test1.sh /bin/sh -c 'sleep 10' >/dev/null 2>&1 &
test2.sh /bin/sh -c 'sleep 10' &
在命令行上使用php运行这两个命令行,如
test1.php <?php shell_exec('test1.sh');
test2.php <?php shell_exec('test2.sh');
看到不同之处。
test2.sh占用10ish秒,test1.sh的工作方式与您的
return shell_exec("/path/to/bash/script arguments >/dev/null 2>&1");
https://stackoverflow.com/questions/39294689
复制相似问题