php high load solution:
When you running a high load website with PHP-FPM via FastCGI, the following tips may be useful to you : )
If you use PHP-FPM to manage FastCGI on a high-load website, these tips may be useful to you:)
1. Compile PHP's modules as less as possible, the simple the best ( fast);
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 4GB memory server);
Adjust your PHP FastCGI child number To 100 or above, 200 is enough on a server with 4G memory.
Note: For my 1g test machine, 64 is the best. It is recommended to use stress testing to obtain the best value
3. Using SOCKET PHP FastCGI, and put into /dev/shm on Linux;
Use socket to connect to FastCGI. The Linux operating system can be placed in /dev/shm.
Related recommendations: "PHP Getting Started Tutorial"
Note: Set
location ~ .*\.(php|php5)?$
{
#Change the communication method between Nginx and FastCGI from TCP to Unix Socket. TCP is more stable than Unix Socket under high concurrent access, but Unix Socket is faster than TCP.
fastcgi_pass unix:/tmp/php-cgi.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
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
To increase the number of files opened by the Linux kernel, you can use these commands (must be the root account)
echo 'ulimit -HSn 65536′ >> /etc/profile
echo 'ulimit -HSn 65536′ >> /etc/rc.local
source /etc/profile
Note: I modified /etc/rc.local and added ulimit -SHn 51200
5. Increase PHP-FPM open file description rlimit:
# vi /path/to/php-fpm.conf
Find “
Change 1024 to 4096 or higher number.
Restart PHP-FPM.
Increase the limit of PHP-FPM open file descriptors:
# vi /path/to/php-fpm.conf
Find "
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.
Using PHP code accelerator, e.g eAccelerator, XCache. You can point `cache_dir` to /dev/shm
The above is the detailed content of What is the solution for high load in php. For more information, please follow other related articles on the PHP Chinese website!