zijidelu 網站日誌目錄/home/hosts_log
記錄檔有對應的網站id
zijidelu php-cgi日誌目錄 /usr/local/php_fcgi/logs
php-fpm.log
slow.log
查看記錄檔基本上就可以解決問題了,我這邊客戶網站是被入侵 上傳了一個php ddos檔案,當然如果不是此問題可以如下查看是不是程式問題有時使用 file_get_contents函數也可能導致cpu 100%哦
在 php.ini 中,有一個參數 max_execution_time 可以設定 PHP 指令碼的最大執行時間,但是,在 php-cgi(php-fpm) 中,該參數不會起效。真正能夠控制 PHP 指令碼最大執行時間的是 php-fpm.conf 設定檔中的以下參數:
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
'0s' means 'off'
<value name="request_terminate_timeout">0s</value>
預設值為 0 秒,也就是說,PHP 指令碼會一直執行下去。這樣,當所有的 php-cgi 進程都卡在 file_get_contents() 函數時,這台 Nginx+PHP 的 WebServer 已經無法再處理新的 PHP 請求了,Nginx 將給使用者返回“502 Bad Gateway”。修改該參數,設定一個 PHP 指令碼最大執行時間是必要的,但是,治標不治本。例如改成 <value name="request_terminate_timeout">30s</value>,如果發生 file_get_contents() 擷取網頁內容較慢的情況,這就意味著 150 個 php-cgi 進程,每秒鐘只能處理 5 個請求,WebServer 同樣很難避免“502 Bad Gateway”。
要做到徹底解決,只能讓 PHP 程式員們改掉直接使用 file_get_contents("http://example.com/") 的習慣,而是稍微修改一下,加個逾時時間,用以下方式來實現 HTTP GET 請求。要是覺得麻煩,可以自行將以下代碼封裝成一個函數。
<?php
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 1 //設定一個逾時時間,單位為秒
)
)
);
file_get_contents("http://www.111cn.net/", 0, $ctx);
?>
當然相如果像dedecms產生html頁面時cpu也會100%的情況哦