PHP-FPM high load technique

Source: Internet
Author: User
[Turn] PHP-FPM high load tips? Go to www.187299.comarchivescategorynginxpage4www.zhiyuanjun.net? P9 is superior to Nginx for high concurrency, so it is configured with Nginx + php-fpm to run the online proxy program. it is configured according to the banquet article and runs normally when the configuration is just completed, but after running for a while, the website [turn] PHP-FPM high load tips

?

Transfer http://www.187299.com/archives/category/nginx/page/4

Http://www.zhiyuanjun.net /? P = 9

Due to Nginx's excellent performance in high concurrency, an Nginx + php-fpm is configured to run the online proxy program. it is configured according to the banquet article and runs normally upon configuration, however, after a period of operation, the website is very slow to open. after you open the website, enter the website you want to access in the input box. When the website is opened slowly, it is also slow to enter commands on the SSH terminal. it is suspected that the network speed of the data center is slow, but enter

W3m www.example.com

This is also slow, and the network speed of the data center can be basically ruled out.

When the website is opened slowly, the server will be restarted quickly.

/Usr/local/webserver/php/sbin/php-fpm restart

Restart fastcgi will also get faster. The most important task is to add fastcgi to the scheduled task. restart every hour to ensure that the website will not be slow, but it is not a solution after all.

View the nginx. log and php-fpm.log, according to the error, find the above reproduced several articles, finally solve the problem, mainly modified two places
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 socket./dev/shm is the memory file system, and it will be faster if it is stored in the memory.

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.