歡迎您光臨本站 註冊首頁

nginx1.0.4+php5.3.5連接不到資料庫的奇怪問題

←手機掃碼閱讀     火星人 @ 2014-03-03 , reply:0

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的配置文件
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),就可以了。但過一段時間又不行了.求解

[火星人 ] nginx1.0.4+php5.3.5連接不到資料庫的奇怪問題已經有492次圍觀

http://coctec.com/docs/service/show-post-1954.html