PHP-FPM parameter Optimization "Go"

Source: Internet
Author: User
Tags fpm server memory

Turn from

PHP-FPM parameter Optimization | Linux OPS Notes
Https://blog.linuxeye.com/380.html

How much is the PHP-FPM process set to fit, dynamic or static?

The LNMP one-click installation package will adjust the number of PHP-FPM processes based on your server memory.

Here is an excerpt from Google discussion topic: "PHP-FPM on Highload Tips" [outside the wall, FQ can refer to goagent].

When you running a highload website with php-fpm via FastCGI, the following tips is useful to you

If your high-load site uses PHP-FPM to manage fastcgi, maybe the following tips are useful for you

1. Compile PHP ' s modules as less as possible, the simple and the best (fast);

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);

Put your PHP fastcgi number of sub-processes to 100 or more, on the 4G memory Server 200 can (recommend stress test to get their own server reasonable value)

3. Using SOCKET PHP FastCGI, and put Into/dev/shm on Linux;

Socket connection Fastcgi,/dev/shm is a memory file system, the socket in memory must be faster

4. Increase Linux "Max open files", using the following command (must be root):

Increase the number of open files under Linux, the command is as follows:

    1. Cat >>/etc/security/limits.conf <<EOF
    2. * Soft Nproc 65535
    3. * Hard Nproc 65535
    4. * Soft Nofile 65535
    5. * Hard Nofile 65535
    6. Eof

5. Increase PHP-FPM Open File Description rlimit:

To increase the limit of PHP-FPM open file descriptors:

    1. # VI $php _install_dir/etc/php-fpm.conf
    2. Rlimit_files = 51200

6. Using PHP Code Accelerator, e.g Eaccelerator, XCache. and set "Cache_dir" To/dev/shm on Linux.

Use PHP code accelerators, such as Eaccelerator, XCache. On the Linux platform, you can point the ' cache_dir ' to/dev/shm

/usr/local/php/etc/php-fpm.conf Important Optimization Parameters Detailed:

    1. PM = Dynamic

The PM parameter specifies how the process is managed, and there are two options: static or dynamic, which is literally not difficult to understand, statically or dynamically. In the case of static mode, the specified number of processes are created when the PHP-FPM is started, and no more changes are made during the run (it is not true forever), while the dynamic is dynamically adjusted during the run and is not unrestricted to create a new process, subject to pm.max_spare_ Servers parameter influence, dynamic fit small memory machine, flexible allocation process, save memory. Static for large memory machines, the dynamic creation of recycling processes to server resources is also a consumption

    1. Pm.max_children =

Number of child processes created in static mode or maximum PHP-FPM child processes allowed at the same time in dynamic mode

    1. Pm.start_servers =

#动态方式下的起始php Number of-FPM processes

    1. Pm.min_spare_servers =

#动态方式下服务器空闲时最小php Number of-FPM processes

    1. Pm.max_spare_servers =

#动态方式下服务器空闲时最大php Number of-FPM processes

The general PHP-FPM process takes up about 20~30m memory and calculates it by 30m. If you run PHP-FPM alone, the dynamic starting value can set the physical memory mem/30m, because everyone general Nginx, MySQL are on a machine, so reserved half to them, that is, the number of PHP-FPM process is $MEM/2/30.

Lnmp parameters on a single machine (for reference only, recommended for stress testing):

    1. Mem= ' Free-m | awk '/mem:/{print ' #我的机器内存是987M
    2. Sed-i "[email protected]^pm.max_children.*@Pm.max_children = $ (($Mem/2/20)) @" $php _install_dir/etc/php-fpm.conf
    3. Sed-i "[email protected]^pm.start_servers.*@pm.start_servers = $ (($Mem/2/30)) @" $php _install_dir/etc/ Php-fpm.conf
    4. Sed-i "[email protected]^pm.min_spare_servers.*@pm.min_spare_servers = $ (($Mem/2/40)) @" $php _install_dir/etc/ Php-fpm.conf
    5. Sed-i "[email protected]^pm.max_spare_servers.*@pm.max_spare_servers = $ (($Mem/2/20)) @" $php _install_dir/etc/ Php-fpm.conf

987M Memory:

    1. PM = Dynamic
    2. Pm.max_children =
    3. Pm.start_servers =
    4. Pm.min_spare_servers =
    5. Pm.max_spare_servers =
Mon Nov 12:03 : 201 CST

PHP-FPM parameter Optimization "Go"

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.