开启左侧

nginx1.0.4+php5.3.5连接不到数据库的奇怪问题

[复制链接]
发表于 2012-2-10 18:39:53 | 显示全部楼层 |阅读模式
nginx1.0.4+php5.3.5
写了个程序
cat test.php
<?php
$a=mysql_connect('sql_ip','user','pass');
if ($a) {
echo "aaa";
} else {
echo "bbb";
}
用web访问显示bbb。php test.php得到aaa
用web访问页面链接不到数据库。使用php命令直接执行可以连接到

nginx错误信息是
2011/09/06 19:50:32 [error] 12764#0: *15800 FastCGI sent in stderr: "PHP Warning: mysql_connect(): Can't connect to MySQL server on 'sql_ip' (4) in /usr/local/website/test.php on line 2" while reading response header from upstream, client: client_ip, server: myurl.com, request: "GET /test.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "sql_ip"

php-fpm的错误信息是:
Sep 05 12:07:41.428903 [WARNING] [pool www] child 6629 exited on signal 15 (SIGTERM) after 497.676413 seconds from start
Sep 05 12:08:27.003124 [WARNING] [pool www] child 6630, script '/usr/local/website/webdata/resource/xy3737-10/xy5final/api/start.php' execution timed out (40.071277 sec), terminating

php-fpm的配置文件
[global]
pid = run/php-fpm.pid
error_log = log/php-fpm_err.log
log_level = warning
emergency_restart_threshold = 10
emergency_restart_interval = 1m
process_control_timeout = 5s
[www]
listen = 127.0.0.1:9000
#listen = /tmp/php-cgi.sock
listen.backlog = 128
listen.owner = shared
listen.group = shared
user = shared
group = shared
pm = static
pm.max_children = 128
pm.start_servers = 32
pm.min_spare_servers = 20
pm.max_spare_servers = 45
pm.max_requests = 1024
pm.status_path = /php_status
request_terminate_timeout = 10s
request_slowlog_timeout = 2
slowlog = var/log/slow.log
rlimit_files = 65535
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

nginx的配置文件
user shared;
worker_processes 4;
error_log logs/error.log;
pid logs/nginx.pid;
worker_rlimit_nofile 65535;
events {
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
server_tokens off;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 128k;
fastcgi_buffers 32 32k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
access_log logs/access.log ;
sendfile on;
keepalive_timeout 65;
}
server {
listen 80 default;
server_name my_url;
location / {
root /usr/local/website;
index index.php index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~^/(php_status)$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
allow all;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/website$fastcgi_script_name;
include fastcgi_params;
}
}

=====================================================
最后我重启了php-fpm(注意是restart不是reload),就可以了。但过一段时间又不行了.求解
平度网:www.pingdu.co 平度论坛:bbs.pingdu.co
发表于 2012-2-10 18:39:57 | 显示全部楼层
怎么最近很多重启就解决问题的怪毛病。。
平度网:www.pingdu.co 平度论坛:bbs.pingdu.co
 楼主| 发表于 2012-2-10 18:39:59 | 显示全部楼层
回复 itxx 的帖子

难道你也是
平度网:www.pingdu.co 平度论坛:bbs.pingdu.co
发表于 2012-2-10 18:40:01 | 显示全部楼层
那应该不是配置的问题,是版本不稳定,换其它版本试试 ?
平度网:www.pingdu.co 平度论坛:bbs.pingdu.co
 楼主| 发表于 2012-2-10 18:40:03 | 显示全部楼层
回复 源泉星火 的帖子

nginx的1.0.4版本和php5.3.5的版本都是稳定版哦
平度网:www.pingdu.co 平度论坛:bbs.pingdu.co
 楼主| 发表于 2012-2-10 18:40:04 | 显示全部楼层
坐等知情人
平度网:www.pingdu.co 平度论坛:bbs.pingdu.co
发表于 2012-2-10 18:40:06 | 显示全部楼层
回复 intgoo 的帖子

稳定版也会有莫名其妙的问题。

多测试几个版本吧!
平度网:www.pingdu.co 平度论坛:bbs.pingdu.co
 楼主| 发表于 2012-2-10 18:40:08 | 显示全部楼层
回复 源泉星火 的帖子

恩。OK。先试试
平度网:www.pingdu.co 平度论坛:bbs.pingdu.co
发表于 2012-2-10 18:40:10 | 显示全部楼层
用的版本都很新啊,我的nginx还用的0.8.呢,php还5.2呢 biggrin.gif
平度网:www.pingdu.co 平度论坛:bbs.pingdu.co
 楼主| 发表于 2012-2-10 18:40:12 | 显示全部楼层
回复 General 的帖子

是因为我之前用这个版本做过。所以我觉得不会有什么问题 mad.gif
平度网:www.pingdu.co 平度论坛:bbs.pingdu.co
您需要登录后才可以回帖 登录 | 会员注册

本版积分规则

 
QQ在线咨询
售前咨询热线
0532-88371356
售后服务微信
pingduwangzhan
快速回复 返回顶部 返回列表