Linux under the php-cgi accounted for memory 100% computer changed a very card solution

Source: Internet
Author: User
Tags fpm ini php script stop script

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

Php-fpm.log

Slow.log

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.

The? 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 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.