Go PHP-FPM High Load skills
?
Turn HTTP://WWW.187299.COM/ARCHIVES/CATEGORY/NGINX/PAGE/4
Http://www.zhiyuanjun.net/?p=9
In the high concurrency of nginx good performance, it is equipped with a NGINX+PHP-FPM to run online agent program, is in accordance with the Zhang Yi article matching, just configured to run normally, but after a period of time, the website opened very slowly, open the site, enter the input box to visit the site, also slow. When the website is slow to open, the input command on the SSH terminal is also slow, suspicion is the computer room speed problem, but on the SSH input
w3m www.example.com
This open also slow, basically can eliminate the computer room speed problem.
When the site is slow to open, restart the server, it will quickly rise, and later found that, with
/USR/LOCAL/WEBSERVER/PHP/SBIN/PHP-FPM restart
Restart the fastcgi will be faster, the most to add it to the scheduled task, restart every hour, the basic guarantee that the site is not slow, but ultimately not the way.
See Nginx.log and Php-fpm.log, according to the error inside, find the above reprinted several articles, finally is to solve the problem, mainly modified two places
1.
Problem:
The limit number of open file descriptors defined in the/usr/local/webserver/php/etc/php-fpm.conf file is found
51200
But with the command ulimit-n view, found only 1024
I have added a/etc/rc.local in the
Ulimit-shn 51200
It didn't come into effect.
Solve:
Vi? /etc/security/limits.conf
The document was finally added
*??????? Soft??? Nofile? 51200
*??????? Hard??? Nofile? 51200
2.
Problem:
With the command
NETSTAT-NP | grep 127.0.0.1:9000 |wc-l
Found only more than 100
Solve:
According to the server memory situation, you can set the number of PHP fastcgi sub-process to 100 or more, on the 4G memory server 200 can be
The memory on the server is 8G, I adjust 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 is open fast and stable.
When you running a highload website with php-fpm via FastCGI, the following tips is useful to you:)
These tips may be useful if you have a high-load site that uses PHP-FPM to manage fastcgi:)
1. Compile PHP ' s modules as less as possible, the simple and the best (fast);
1. Install PHP modules as little as possible, the simplest is the best (fast)
2. Increas PHP FastCGI Child number to + even more. Sometime, ok! (on 4GB memory server);
2. Set your PHP fastcgi sub-process number to 100 or above, on the 4G memory server 200 can
Note: My 1g test machine, open 64 is the best, recommended to use the pressure test to obtain the best value
3. Using SOCKET PHP FastCGI, and put Into/dev/shm on Linux;
3. Using the socket connection Fastcgi,linux operating system can be placed in/DEV/SHM
Note: In the php-fpm.cnf set /tmp/nginx.socket can be connected through the socket fastcgi,/DEV/SHM is a memory file system, put in memory will certainly be fast
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 open files in the Linux kernel, you can use these commands (must be the root account)
echo ' ulimit-hsn 65536′>>/etc/rc.local
SOURCE/ETC/PROFILE
Note: I'm modifying/etc/rc.local, adding Ulimit-shn 51200
5. Increase PHP-FPM Open File description rlimit:
# vi/path/to/php-fpm.conf
find " 1024x768 "
change 1024x768 to 4096 or H Igher number.
restart php-fpm.
# vi/path/ TO/PHP-FPM.CONF
find " 1024x768 "
change the 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, XCache. On the Linux platform, you can point the ' cache_dir ' to/dev/shm