现象:

PHP查询数据库较慢,大约 60s 后 nginx 返回 504:Sorry, the page you are looking for is currently unavailable.

检查log:

从 /etc/nginx/nginx.conf 找到 /var/log/nginx/access.log 和 /var/log/nginx/error.log

log 显示 upstream timed out (110: Connection timed out) while reading response header from upstream

解决办法:

Nginx upstream timed out (why and how to fix)

添加带有注释的语句

    location ~ \.php$ {
# root html;
fastcgi_read_timeout 300; #########https://distinctplace.com/2017/04/22/nginx-upstream-timed-out/ upstream timed out (110: Connection timed out) while reading response header from upstream
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

执行 service nginx reload 之后,执行查询,返回页面没有显示 table,继续检查log

"PHP message: PHP Warning: file_get_contents(http://127.0.0.1/xxx): failed to open stream: HTTP request failed! in /home/www/uninum/web.php on line 50

PHP message: PHP Notice:  Trying to get property of non-object in xxx.php on line 54" while reading response header from upstream

同步设置  file_get_contents 超时

php file_get_contents 获取文件超时的处理方法  以及post 和 多次重试

$opts = array(
'http'=>array(
'method'=>"GET",
'timeout'=>300,
) );
$context = stream_context_create($opts);
$html =file_get_contents('http://www.example.com', false, $context);

PHP查询数据库较慢,nginx 超时 返回 504:Sorry, the page you are looking for is currently unavailable.的更多相关文章

  1. Nginx报错:Sorry, the page you are looking for is currently unavailable. Please try again later.

    查看了进程, nginx, php-fpm都在运行, 排除程序错误, 那么就是配置的问题了. 一个可能的错误, 是由于配置中的 fastcgi_pass 配置错了 错误的配置如下 server { l ...

  2. 浏览器给openresty连接发送参数请求,查询数据库,并返回json数据

    nginx.conf配置文件 #user nobody; worker_processes 1; error_log logs/error.log; #error_log logs/error.log ...

  3. python查询数据库返回数据

    python查询数据库返回数据主要运用到flask框架,pymysql 和 json‘插件’ #!/usr/bin/python # -*- coding: UTF-8 -*- import pymy ...

  4. 【问题记录】MyBatis查询数据库返回多个不同类型参数的结果集的接收方式

    其实是个非常简单的问题,但是这玩意儿弄得我很难受,又浪费了一个下午的时间,简直了…… 问题大概是,我在查询数据库时,查询的结果有两个,一个是varchar格式的字段,一个int格式字段,例如: sel ...

  5. shell脚本中sqlite3命令查询数据库失败返回空,并将错误信息打印到标准错误输出

    shell脚本中sqlite3命令查询数据库失败返回空,并将错误信息打印到标准错误输出 如: #/bin/sh local ret='sqlite3 test.db "select test ...

  6. mybatis学习----------查询数据库返回结果为空

    用mybits查询数据库时,如果参数已传入sql,sql也已经执行了,但是返回结果为空,首先保证数据库中有对应数据,如果有对应数据仍返回null,是数据库配置文件有问题.解决方案如下:1.mapper ...

  7. python3.6 + selenium2.53.1 查询数据库并将返回的内容中每一行的内容转换成class对象

    环境: win10 python3.6 selenium2.53.1 准备工作:先安装pymysql python2.x链接数据库使用MySQLdb,而python3.x链接数据库使用pymysql ...

  8. laravel 查询数据库first()返回的数据转数组

    使用 get_object_vars()可以将他抓转为数组get_object_vars — 返回由对象属性组成的关联数组: 在laravel中其实还可以用 toArray(); json_decod ...

  9. Django 1.8.11 查询数据库返回JSON格式数据

    Django 1.8.11 查询数据库返回JSON格式数据 和前端交互全部使用JSON,如何将数据库查询结果转换成JSON格式 环境 Win10 Python2.7 Django 1.8.11 返回多 ...

随机推荐

  1. lua 中随机数产生

    需要用到两个函数: (1)math.randomseed(N):  接收一个整数N作为随机序列种子 (2)math.random([n, [m]]): 这个函数有三种用法,分别是不跟参数,此时产生(0 ...

  2. springcloud-3:required a bean of type 'com.netflix.discovery.DiscoveryClient' that could not be found.

    在写客户端程序的时候,总是报'com.netflix.discovery.DiscoveryClient' that could not be found. 原因在于导入了错误的类:com.netfl ...

  3. 前端-----JavaScript 初识基础

    JavaScript的组成 JavaScript基础分为三个部分: ECMAScript:JavaScript的语法标准.包括变量.表达式.运算符.函数.if语句.for语句等. DOM:操作网页上的 ...

  4. [转]phpstorm激活码注册码序列号

    浏览器打开 http://idea.lanyus.com/ , 点击页面中的“获得注册码”,然后在注册时切换至Activation Code选项,输入获得的注册码一长串字符串,就可以注册成功!(推荐方 ...

  5. 将list集合转json

    public static class DataHelper { /// /// js 序列化器 /// static JavaScriptSerializer jss = new JavaScrip ...

  6. HashMap遍历的两种方式,推荐使用entrySet()

    第一种: Map map = new HashMap(); Iterator iter = map.entrySet().iterator(); while (iter.hasNext()) {    ...

  7. 注册InstallShield

    安装InstallShield 下载installshield limitededition版本,这个版本是免费的 注册 安装打开后会给一个网址要求进行注册 其中,国籍是必填项但是下拉菜单中没有内容, ...

  8. C语言学习及应用笔记之二:C语言static关键字及其使用

    C语言有很多关键字,大多关键字使用起来是很明确的,但有一些关键字却要相对复杂一些.我们这里要说明的static关键字就是如此,它的功能很强大,相应的使用也就更复杂. 一般来说static关键字的常见用 ...

  9. /etc/rc.d/init.d/iptables: No such file or directory 错误原因

    注:本文转载自cnblogs:一天学点的文章</etc/rc.d/init.d/iptables: No such file or directory 错误原因> RedHat Enter ...

  10. Confluence 6 开始使用

    欢迎来到 Confluence 的开始使用指南文档.在这个稳定中,你将会找到有关对 Confluence 进行评估的指南和其他的一些有用的内容.当你开始使用 Confluence 的时候,这些信息能够 ...