Nginxphp-fpm optimization

Source: Internet
Author: User
Nginxphp-fpm optimization 1,
Problem:
Found that the limit on the number of opened file descriptors defined in the/usr/local/webserver/php/etc/php-fpm.conf file is
51200
However, you can run the command ulimit-n to check whether it is only 1024.

I have added/etc/rc. local
Ulimit-SHn 51200

Not effective

Solution:
Vi/etc/security/limits. conf

Add
* Soft nofile 51200
* Hard nofile 51200

2,
Problem:
Use commands

Netstat-np | grep 127.0.0.1: 9000 | wc-l

Only over 100

Solution:
Depending on the server memory, you can adjust the number of PHP FastCGI sub-processes to 100 or more, and 200 on the 4G memory server.
The memory on the server is 8 GB. I adjusted the number of PHP FastCGI sub-processes to 300.

Vi/usr/local/webserver/php/etc/php-fpm.conf
Change max_children to 300
300

Restart the server so that the website can be opened quickly and stably.

When you running a highload website with PHP-FPM via FastCGI, the following tips may be useful to you :)
These tips may be useful to you if your high-load website uses PHP-FPM manager FastCGI :)

1. Compile PHP's modules as less as possible, the simple the best (fast );
1. install as few PHP modules as possible. The simplest is the best (fast ).

2. Increas PHP FastCGI child number to 100 and even more. Sometime, 200 is OK! (On 4 GB memory server );
2. adjust the number of PHP FastCGI sub-processes to 100 or above and 200 on the 4G memory server.
Note: for my 1G testing machine, 64 is the best. we recommend that you use stress testing to obtain the best value.

3. Using socket php FastCGI, and put into/dev/shm on Linux;
3. use socket to connect to FastCGI. the linux operating system can be stored in/dev/shm.
Note: Set in php-fpm.cnf /Tmp/nginx. socket You can connect to FastCGI through the socket./dev/shm is the memory file system, and it will be faster to put it in the memory (this step is to be confirmed)

4. Increase Linux "max open files", using the following command (must be root ):
# Echo 'ulimit-HSn 65536 '>/etc/profile
# Echo 'ulimit-HSn 65536>/etc/rc. local
# Source/etc/profile
4. increase the number of files opened in the Linux kernel. you can use these commands (the root account must be used)
Echo 'ulimit-HSn 65536 '>/etc/profile
Echo 'ulimit-HSn 65536 '>/etc/rc. local
Source/etc/profile
Note: I modified/etc/rc. local and added it to ulimit-SHn 51200.

5. Increase PHP-FPM open file description rlimit:
# Vi/path/to/php-fpm.conf
Find" 1024 "
Change 1024 to 4096 or higher number.
Restart PHP-FPM.
5. added restrictions on opening file descriptors for PHP-FPM:
# Vi/path/to/php-fpm.conf
Find" 1024 "
Change 1024 to 4096 or higher.
Restart PHP-FPM.


6. Using PHP code accelerator, e. g eAccelerator, XCache. And set "cache_dir" to/dev/shm on Linux.
6. use php code accelerators, such as eAccelerator and XCache. on the linux platform, you can point 'cache _ dir' to/dev/shm.

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.