What is the solution for high load in php

爱喝马黛茶的安东尼
Release: 2023-02-23 12:44:01
Original
4527 people have browsed it

What is the solution for high load in php

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 /tmp/nginx in php-fpm.cnf .socket can connect to FastCGI through socket. /dev/shm is a memory file system, and it will definitely be faster if it is placed in memory. Remember to modify the configuration in nginx at this time to keep it consistent.

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 “ 1024

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 "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.

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template