When the Linux system is in use, the computer becomes very card, found that the php-cgi process is occupying cpu, the occupancy rate has reached 100%, what is it? What causes this situation? The following small series will introduce you to the Linux system php-cgi takes up 100% of the solution.
Web logs directory /home /hosts_log
log file has a corresponding website id
php-cgi log directory /usr /local /php_fcgi /logs
php-fpm.log
slow.log
Viewing the log file basically solves the problem, the website is hacked and uploaded a php ddos file, of course, if this is not the problem You can check if it is a program problem. Sometimes using the file_get_contents function may also cause the cpu to be 100%.
In php.ini, there is a parameter max_execution_time that sets the maximum execution time of a PHP script, but in php-cgi(php-fpm) this parameter won't work. The only parameter in the php-fpm.conf configuration file that really controls the maximum execution time of a PHP script is:
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"
The default value is 0 seconds, which means that the PHP script will continue to execute. Thus, when all php-cgi processes are stuck in the file_get_contents() function, the Nginx+PHP WebServer can no longer process new PHP requests, and Nginx will return "502 Bad Gateway" to the user. Modifying this parameter and setting a maximum execution time for a PHP script is necessary, but the palliative is not a cure. For example, change to "value name=“request_terminate_timeout”"30s "/value". If file_get_contents() occurs to get slower web content, this means 150 php-cgi processes, which can only process 5 per second. Requests, WebServer is also difficult to avoid < 502 Bad Gateway”.
To be completely solved, you can only change the habit of directly using file_get_contents, but modify it a bit, add a timeout, and implement HTTP GET request in the following way. If you feel trouble, you can package the following code into a function.
"? Php
$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 the html page is generated like dedecms, the cpu will also be 100%.
Linux php-cgi process takes up 100% of the solution to the cpu introduced here, there is a possibility of poisoning, which requires anti-virus treatment.
PHP Trojan is mainly used to attack websites. It will insert code into the website.
uGet is a download artifact similar to Thunder in Linux, and the new version of uGet2 will have more
gmtime and localtime are two different functions. Many people are confused when usi
for FreeBSD 8.2 Salt is a large-scale distributed configuration management system. After installing
How Linux implements the transmission of UDP broadcast messages
Little-known Unix command inventory
Linux how to use the text processing tool awk
How to modify the character set in Linux
How Linux Expands Disks under VMware
Ubuntu uses SHA256 to verify instances of iso image integrity
CentOS 6.5 install wireless network card driver tutorial
How Linux can improve the copying efficiency of large files
How to install vsftpd server under Linux
Linux system svn operation example
Several ways to clean up the Win8 system!
Awk string concatenation operation (string to number, number to string)
Unable to enter XP, prompting hal.dll to be damaged or missing
The latest processor Windows8 device is available in the year
After the Win10 system sets the computer background, the desktop icon is hidden. How to restore
How to convert qsv format to rmvb
How to install Win10 system to U disk
How to solve the problem of Windows7 "Error 16389, unable to create a new library"