so_brave 发表于 2011-09-12 21:40

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

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


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 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 child 6629 exited on signal 15 (SIGTERM) after 497.676413 seconds from start
Sep 05 12:08:27.003124 child 6630, script '/usr/local/website/webdata/resource/xy3737-10/xy5final/api/start.php' execution timed out (40.071277 sec), terminating

php-fpm的配置文件

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

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
env = /usr/local/bin:/usr/bin:/bin
env = /tmp
env = /tmp
env = /tmp

nginx的配置文件
usershared;
worker_processes4;
error_loglogs/error.log;
pid      logs/nginx.pid;
worker_rlimit_nofile 65535;
events {
    worker_connections65535;
}
http {
    include       mime.types;
    default_typeapplication/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_loglogs/access.log ;
    sendfile      on;
    keepalive_timeout65;
}
    server {
      listen       80 default;
      server_namemy_url;
      location / {
            root   /usr/local/website;
            indexindex.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_indexindex.php;
            fastcgi_paramSCRIPT_FILENAME/usr/local/website$fastcgi_script_name;
            include      fastcgi_params;
      }
    }

=====================================================
最后我重启了php-fpm(注意是restart不是reload),就可以了。但过一段时间又不行了.求解
页: [1]
查看完整版本: nginx1.0.4+php5.3.5连接不到数据库的奇怪问题