尝试从php运行phantomjs脚本时,nginx抛出“504”网关错误

时间:2015-02-10 14:34:58

标签: php linux nginx phantomjs server

我正试图像这样运行phantomjs脚本:

$max_time = ini_get('max_execution_time');
set_time_limit(0);
$result = shell_exec($path_to_phantomjs);
// Do stuff with result here...
set_time_limit($max_time);

这是一个需要几分钟才能完成的抓取脚本,但我想等待它的结果并在我的服务器上操作它。对我来说,这个脚本将从客户端运行并将一些结果返回给它进行分析等也很重要。

这失败了来自nginx的504错误,应该注意相同的代码在我的(本地)apache服务器上运行良好。

1 个答案:

答案 0 :(得分:1)

504错误意味着从后端(php)获取页面时nginx达到超时。要解决此问题,您应该将php代理位置中以下变量的值增加到高于执行脚本的时间(以秒为单位):

fastcgi_read_timeout

proxy_read_timeout