发布于 2016-02-13 05:04:28 | 326 次阅读 | 评论: 1 | 来源: 网友投递

这里有新鲜出炉的Nginx开发从入门到精通,程序狗速度看过来!

Nginx WEB服务器

Nginx 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。


这篇文章主要介绍了Nginx PHP-Fcgi中因PHP执行时间导致504 Gateway Timeout错误解决记录,本文的解决方法得来不易,需要的朋友可以参考下

昨天,一个程序需要导出500条数据,结果发现到150条是,Nginx报出504 Gateway Timeout错误

经观察,发现大约30秒时超时,php.ini中执行时间配置已经是300秒:



max_execution_time = 300

再查nginx的相关配置,无果。

写了一个php的测试页再测:



echo 'aaa';

set_time_limit(0);

sleep(40);

echo 'aa';

依然超时,可以确定set_time_limit这个函数没生效。

再查php-fcgi的配置php-fpm.conf,下边这个设置疑似有问题:



<value name="request_terminate_timeout">30s</value>

查官方文档:http://php-fpm.org/wiki/Configuration_File



request_terminate_timeout - The timeout (in seconds) for serving a single request after which the worker process will be terminated. Should be used when 'max_execution_time' ini option does not stop script execution for some reason. Default: "5s". Note: '0s' means 'off'

大意是php中set_time_limit设置的时间内如果php还没执行完,则走此处的配置,也就是request_terminate_timeout=30秒。

先把这个参数改的和php中set_time_limit值一样,都是300秒,还不行,不理解为什么,如果高手知道请赐教。

最终把request_terminate_timeout关闭,程序可以正常执行了,问题解决:



<value name="request_terminate_timeout">0s</value>

补充:如果前端的nginx服务器使用了upstream负载均衡,那个负载均衡配置中以下几个参数也需要相应修改:



proxy_connect_timeout       300s;

proxy_send_timeout          300s;

proxy_read_timeout          300s;



最新网友评论  共有(1)条评论 发布评论 返回顶部
asmc 发布于2016-06-28 12:28:24
不错,收藏。
支持(0)  反对(0)  回复

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务