PHP-FPM high load techniques (PHP-FPMonhighloadtips) original address: hi.baidu.compibuchoublogitem7cbccff0a3b77dc60b46e024.html? Cause nginx502badgateway PHP-CGI (FASTCGI) NGINX frequency burst 502 bad0000wa PHP-FPM high load techniques (PHP-FPM on highload tips)
Address: http://hi.baidu.com/pibuchou/blog/item/7cbccff0a3b77dc60b46e024.html
?
Cause the PHP-CGI of nginx 502 bad gateway (FASTCGI)
The error of NGINX frequently exploding 502 bad gateway is still not completely solved after reading the online tutorial.
Currently, I have summarized the following methods to solve the 502 BAD GATEWAY problem:
1. depending on the server performance, add max_children value in the php-fmp.conf, I currently use 15.
2. use the reload parameter to regularly reload php-fpm. This is mainly because php scripts are executed for a long time. This problem can be eliminated by reloading php-fpm. It is worth further exploring how to completely solve the 502 error caused by a large amount of memory occupied by the php-cgi script. Currently, this method is a good solution.
The specific method is to use crontab to smoothly restart php-fpm without affecting the running of PHP scripts.
*/10 */usr/local/php/sbin/php-fpm reload
?
?
When you running a highload website? PHP-FPM? Via FastCGI, the following tips may be useful to you :)
These tips may be useful to you if your high-load website manages FastCGI using a PHP-FPM :)
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. add? PHP-FPM? Restrictions on opening file descriptors:
# 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.
?