Linux file handle number leads to php-cgi suspended animation problem Solving tutorial

Source: Internet
Author: User
Tags fpm time limit

Recently, a production of the server (CentOS 5.2 64-bit 4G memory), always appear in the Web site can not open, log on to the server to view, found Nginx and php-cgi are running, and usually different is at this time php-cgi CPU occupied 0, immediately view the file handle number limit
Ulimit-n
The results are: 1024, this value for the production of services appear to be small.
Most of the solutions given online are directly input
Ulimit-shn 51200 # 51200 can be adjusted according to your application
The disadvantage of this method is obvious, once you exit the landing, the setting is invalidated.
There are also said to write the order directly into the/etc/rc.d/rc.local, today to find a correct way
Open/etc/security/limits.conf, which has a very detailed comment, find the following settings (if not inserted)

The code is as follows Copy Code
* Soft Nofile 51200
* Hard Nofile 51200

Log in again after exiting and view the number of handles, which has been correctly set to 51200.

If you encounter a similar situation, you can check to see if the file handle number set too small caused.


solution to 502 bad Gateway when accessing

Nginx 502 Bad Gateway means that the requested php-cgi has been executed, but the php-cgi process is terminated for some reason (typically a problem reading the resource) is not completed. This error can be easily seen in a Web site that is typically too high on the concurrent number. There are many reasons for the 502 bad gateway, but the larger part
Modify the following parameters to resolve.
Change several configuration items for Nginx, reduce the number of FASTCGI requests, and try to maintain buffers unchanged:

The code is as follows Copy Code


Fastcgi_buffer_size 128k;
Fastcgi_buffers 2 256k;
Fastcgi_busy_buffers_size 256k;
Fastcgi_temp_file_write_size 256k;

Open the/usr/local/php/etc/php-fpm.conf file and modify the following parameters:

The code is as follows Copy Code


<value name= "Max_children" >25</value>
<value name= "Max_requests" >2048</value>
<value name= "Rlimit_files" >65535</value>

<value name= "Process_control_timeout" >30s</value>
<value name= "Request_terminate_timeout" >60s</value>

<value name= "Style" >apache-like</value>

Request_terminate_timeout refers to the fast-cgi execution script time, which defaults to 0s. The meaning of 0s is to allow php-cgi to carry on without any time limit. If you set this to 0s, the 502 state will not change when the 502 bad gateway appears. But if you set it to 5s, then the php-cgi will automatically resume when it's suspended in 5s. This value can be set according to the performance of your server, where I set the 60s.

The

Max_children represents the processing process for php-cgi. If the Max_children set smaller, such as 5-10, then php-cgi will be "very tired", processing speed is also very slow, waiting for a long time. A 504 Gateway time-out error occurs if the request is not processed for a long time. Set Max_children also need to set according to the performance of the server, increase the number of processes, memory consumption will be increased, the normal situation of each php-cgi memory in about 20M, here I set is 25. The default static handling of the
PHP-FPM can cause php-cgi processes to occupy memory for a long time and not be released, which is one of the causes of nginx errors, so that the PHP-FPM processing is changed to Apache-like mode. The
Modify completes execution Lu-restart (Lumanager Server Management System).

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.