Linux system in use, the computer becomes very card, found that the php-cgi process in the CPU, occupancy rate since reached 100%, what is the reason for this situation? The following small series for you to introduce the Linux system php-cgi occupy CPU hundred percent solution.
Web site Log directory/home/hosts_log
The log file has a corresponding site ID
php-cgi Log Directory/usr/local/php_fcgi/logs
Viewing log files can basically solve the problem, the site was invaded upload a php DDoS file, of course, if not this issue can be viewed as follows is not a program problem sometimes using the file_get_contents function may also lead to CPU 100%.
In PHP.ini, there is a parameter max_execution_time can set the maximum execution time for a PHP script, but in php-cgi (PHP-FPM), the parameter does not work. The real ability to control the maximum execution time of a PHP script is the following parameters in the php-fpm.conf configuration file:
The timeout (in seconds) to serving a single request after the which the worker process would be terminated
Should be used as ' max_execution_time ' ini option does not stop script execution for some reason
' 0s ' means ' off '
"Value name=" request_terminate_timeout "0s"/value "
The default value is 0 seconds, which means that the PHP script will continue to execute. In this way, when all the php-cgi processes are stuck in the file_get_contents () function, the webserver of this nginx+php is no longer able to process the new PHP request, and Nginx will return "502 bad Gateway" to the user. Modify this parameter to set a PHP script maximum execution time is necessary, but the symptom does not cure the root causes. For example, change to the value name= "request_terminate_timeout" 30s "/value", if file_get_contents () get the content of the Web page is slow, which means that 150 php-cgi process, Only 5 requests per second can be processed, webserver also difficult to avoid "502 bad Gateway."
To achieve a thorough solution, you can only get rid of the habit of directly using file_get_contents, but slightly modified, plus a time-out, the following ways to implement HTTP gets request. If you find yourself in trouble, you can encapsulate the following code as a function.
$ctx = stream_context_create (Array (
' http ' = ' Array (
' Timeout ' = 1//Set a timeout in seconds
File_get_contents ("http://www.111cn.net/", 0, $ctx);
Of course, if you generate HTML pages like DEDECMS, the CPU will also be 100%.
Linux under the php-cgi process to occupy the CPU hundred percent of the solution is introduced here, there is a possible poisoning caused, which requires anti-virus treatment.