Join the community today
Register Now

PHP-FPM Multiple PHP-FPM Pools Generator Script testing

Discussion in 'Beta release code' started by eva2000, Aug 2, 2014.

  1. eva2000

    eva2000 Administrator Staff Member

    54,600
    12,225
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,794
    Local Time:
    3:52 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Another beta testing item I whipped up. Basically, it's shell script to auto generate as many PHP-FPM pools as you need each with their own dedicated PHP-FPM config file, log files, unix socket and TCP port assigned.

    The TCP port assignment starts at 91xx and auto increments by 01 for each additional PHP-FPM pool. So if you choose to have 2 PHP-FPM pools generated (PHP_POOL=2 variable in phppoolgen.sh), you'd have each PHP-FPM pool on 9100 and 9101 TCP ports respectively. Edit: Ah I need to factor in existing TCP 91XX port detection so if the script is ran a second time, it starts off from last added multi PHP-FPM pool TCP ports.

    The phppoolgen.sh script isn't being released as yet just doing internal testing for now to see how it goes. Wrote the script as it's alot easier to have written it that to explain step by step in manually creating multiple PHP-FPM pools for Centmin Mod Nginx :D


    Once phppoolgen.sh is run a few files are created. Using below output as a specific example.
    1. /root/tools/multiphp_pools/multiphp_pools_info_310714-235154.txt - is a summary file listing each PHP-FPM pools crucial and unique info including where the PHP-FPM config file is for that specific pool i.e. /usr/local/nginx/conf/phpfpmd/multiphp_pool0.conf. Also lists the curl command to pull PHP-FPM stats from.
    2. /root/tools/multiphp_pools/multiphp_pools_stats_cmds_310714-235154.txt - file lists all PHP-FPM pools SSH command to curl grab each PHP-FPM Pools stats. You can use it to run all commands in a shell script to pull all PHP-FPM pools stats all at once.
    3. /usr/local/nginx/conf/multiphp_status.conf - multi PHP-FPM pools php status and ping location contexts. You include this file in main server's hostname Nginx vhost file at /usr/local/nginx/conf/conf.d/virtual.conf. You'd need this along with uncommenting the allow #youripaddress and filling in youripaddress to be able to view your PHP-FPM pool's php status info at http://yourhostname/phpstatus_poolX where X is the PHP-FPM pool number. More PHP status info at PHP-FPM - pm.max_children | Centmin Mod Community
    4. /root/tools/multiphp_pools/cleanup_cmds_310714-235154.sh - the cleanup_cmds_XX.sh shell script. Basically, running it removes all created multi PHP-FPM pools and reverts your environment as close to previous state as possible. Still manual steps involved to change back /usr/local/nginx/conf/php.conf include file's fastcgi_pass value to 127.0.0.1:9000.
    5. /usr/local/nginx/conf/multiphp_upstream.conf - the include file for the PHP-FPM pool upstream load balanced backend named multiphp_backend. This needs to be included in /usr/local/nginx/conf/nginx.conf after the http { for you to be able to use the multiple PHP-FPM pools in load balanced configuration.
    6. /usr/local/nginx/conf/phpfpmd/ - is the directory where the multiple PHP-FPM config *.conf files are located
    phppoolgen.sh variables
    Code:
    PHP_POOLS='2'
    
    # Default values for pm.max_children and pm.max_requests
    # info at https://community.centminmod.com/threads/pm-max_children.479/#post-2036
    # PM_MODE choices are ondemand, static or dynamic
    # for multi PHP pools set static
    PM_MODE='static'
    PHP_MAXCHILDREN='4'
    PHP_MAXREQUESTS='2000'
    
    # default PHP-FPM pool user and group
    # default is nginx:nginx for user:group
    # if changing user/group, the user and group must
    # already exist first
    PHP_USER='nginx'
    PHP_GROUP='nginx'
    Code:
    ./phppoolgen.sh
    
    -----------------------------------------------------------------------
    created summary multi PHP-FPM pool info file at:
    /root/tools/multiphp_pools/multiphp_pools_info_310714-235154.txt
    
    Thu Jul 31 23:51:54 UTC 2014
    ####################################
    Summary for php_pool0 pool:
    ####################################
    File location = /usr/local/nginx/conf/phpfpmd/multiphp_pool0.conf
    
    SSH command to view php_pool0 pool stats
    curl --silent --connect-timeout 5 --max-time 5 127.0.0.1/phpstatus_pool0
    
    [php_pool0]
    PHP_PORT=9100
    listen = 127.0.0.1:9100
    ;listen = /tmp/multi_php-fpm0.sock
    slowlog = /var/log/php-fpm/multiphp-slow0.log
    pm.status_path = /phpstatus_pool0
    ping.path = /phpping_pool0
    /var/log/php-fpm/multiphp.error0.log
    
    ####################################
    Summary for php_pool1 pool:
    ####################################
    File location = /usr/local/nginx/conf/phpfpmd/multiphp_pool1.conf
    
    SSH command to view php_pool1 pool stats
    curl --silent --connect-timeout 5 --max-time 5 127.0.0.1/phpstatus_pool1
    
    [php_pool1]
    PHP_PORT=9101
    listen = 127.0.0.1:9101
    ;listen = /tmp/multi_php-fpm1.sock
    slowlog = /var/log/php-fpm/multiphp-slow1.log
    pm.status_path = /phpstatus_pool1
    ping.path = /phpping_pool1
    /var/log/php-fpm/multiphp.error1.log
    
    
    -----------------------------------------------------------------------
    created php status SSH cmds list file at:
    /root/tools/multiphp_pools/multiphp_pools_stats_cmds_310714-235154.txt
    
    curl --silent --connect-timeout 5 --max-time 5 127.0.0.1/phpstatus_pool0
    curl --silent --connect-timeout 5 --max-time 5 127.0.0.1/phpstatus_pool1
    
    -----------------------------------------------------------------------
    created phpstatus config file at:
    /usr/local/nginx/conf/multiphp_status.conf
    
    Thu Jul 31 23:51:54 UTC 2014
    location ~ ^/(phpstatus_pool0|/phpping_pool0)$ {
        access_log       off;
        #fastcgi_pass    unix:/tmp/multi_php-fpm0.sock;
        fastcgi_pass     127.0.0.1:9100;
        fastcgi_param    SCRIPT_FILENAME ;
        include          fastcgi_params;
        allow  127.0.0.1;
        #allow yourstaticipaddress;
        deny    all;
    }
    
    location ~ ^/(phpstatus_pool1|/phpping_pool1)$ {
        access_log       off;
        #fastcgi_pass    unix:/tmp/multi_php-fpm1.sock;
        fastcgi_pass     127.0.0.1:9101;
        fastcgi_param    SCRIPT_FILENAME ;
        include          fastcgi_params;
        allow  127.0.0.1;
        #allow yourstaticipaddress;
        deny    all;
    }
    
    
    -----------------------------------------------------------------------
    created cleanup_cmds_310714-235154.sh script at:
    /root/tools/multiphp_pools/cleanup_cmds_310714-235154.sh
    
    #!/bin/bash
    rm -rf /usr/local/nginx/conf/multiphp_upstream.conf
    rm -rf /usr/local/nginx/conf/multiphp_status.conf
    #rm -rf /root/tools/multiphp_pools/multiphp_pools_info_310714-235154.txt
    #rm -rf /root/tools/multiphp_pools/multiphp_pools_stats_cmds_310714-235154.txt
    rm -rf /usr/local/nginx/conf/phpfpmd/multiphp_pool0.conf
    rm -rf /var/log/php-fpm/multiphp-slow0.log
    rm -rf /var/log/php-fpm/multiphp.error0.log
    rm -rf /usr/local/nginx/conf/phpfpmd/multiphp_pool1.conf
    rm -rf /var/log/php-fpm/multiphp-slow1.log
    rm -rf /var/log/php-fpm/multiphp.error1.log
    
    -----------------------------------------------------------------------
    created php backup upstream file at:
    /usr/local/nginx/conf/multiphp_upstream.conf
    
    upstream multiphp_backend {
    ip_hash;
    keepalive 16;
    server 127.0.0.1:9100 weight=10 max_fails=5 fail_timeout=10;
    server 127.0.0.1:9101 weight=10 max_fails=5 fail_timeout=10;
    }
    
    -----------------------------------------------------------------------
    created 2 PHP-FPM pool config files
    in directory /usr/local/nginx/conf/phpfpmd/
    total 16K
    drwxr-xr-x 2 root root 4.0K Jul 31 23:51 .
    drwxr-xr-x 5 root root 4.0K Jul 31 23:51 ..
    -rw-r--r-- 1 root root 1.6K Jul 31 23:51 multiphp_pool0.conf
    -rw-r--r-- 1 root root 1.6K Jul 31 23:51 multiphp_pool1.conf
    
    -----------------------------------------------------------------------
    edit /usr/local/nginx/conf/nginx.conf and add include file
    /usr/local/nginx/conf/multiphp_upstream.conf
    
    below and after http {
    
    http {
    include /usr/local/nginx/conf/multiphp_upstream.conf;
    
    -----------------------------------------------------------------------
    edit /usr/local/nginx/conf/conf.d/virtual.conf and add include file
    /usr/local/nginx/conf/multiphp_status.conf
    
    below existing include files so looks like
    
    include /usr/local/nginx/conf/staticfiles.conf;
    include /usr/local/nginx/conf/php.conf;
    #include /usr/local/nginx/conf/phpstatus.conf;
    include /usr/local/nginx/conf/drop.conf;
    #include /usr/local/nginx/conf/errorpage.conf;
    include /usr/local/nginx/conf/multiphp_status.conf;
    
    -----------------------------------------------------------------------
    edit /usr/local/nginx/conf/php.conf include file and change fastcgi_pass
    value 127.0.0.1:9000 to use multiphp_backend defined
    in /usr/local/nginx/conf/multiphp_upstream.conf
    
    fastcgi_pass   127.0.0.1:9000;
    
      becomes
    
    fastcgi_pass   multiphp_backend;
    
    -----------------------------------------------------------------------
    edit /usr/local/etc/php-fpm.conf and uncomment this line
    
    from
    
    ;include=/usr/local/nginx/conf/phpfpmd/*.conf
    
    becomes
    
    include=/usr/local/nginx/conf/phpfpmd/*.conf
    
    -----------------------------------------------------------------------
    restart both nginx and php-rpm for changes to take effect
    command shortcut = nprestart
    
    -----------------------------------------------------------------------
    to remove all created multi PHP-FPM pool files and revert to previous
    state, revert change in /usr/local/nginx/conf/php.conf and run cleanup script
    at: /root/tools/multiphp_pools/cleanup_cmds_310714-235154.sh
    sample contents from /usr/local/nginx/conf/phpfpmd/multiphp_pool0.conf
    Code:
    [php_pool0]
    user = nginx
    group = nginx
    
    listen = 127.0.0.1:9100
    ;listen.allowed_clients = 127.0.0.1
    ;listen.backlog = -1
    listen.backlog = 131072
    
    ;listen = /tmp/multi_php-fpm0.sock
    listen.owner = nginx
    listen.group = nginx
    listen.mode = 0666
    
    pm = static
    pm.max_children = 4
    ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
    pm.start_servers = 1
    pm.min_spare_servers = 1
    pm.max_spare_servers = 3
    pm.max_requests = 2000
    
    rlimit_files = 131072
    rlimit_core = 0
    
    ; The timeout for serving a single request after which the worker process will
    ; be killed. This option should be used when the 'max_execution_time' ini option
    ; does not stop script execution for some reason. A value of '0' means 'off'.
    ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
    ; Default Value: 0
    ;request_terminate_timeout = 0
    ; Default Value: 0
    ;request_slowlog_timeout = 0
    slowlog = /var/log/php-fpm/multiphp-slow0.log
    
    pm.status_path = /phpstatus_pool0
    ping.path = /phpping_pool0
    ping.response = pong
    
    ; Limits the extensions of the main script FPM will allow to parse. This can
    ; prevent configuration mistakes on the web server side. You should only limit
    ; FPM to .php extensions to prevent malicious users to use other extensions to
    ; exectute php code.
    ; Note: set an empty value to allow all extensions.
    ; Default Value: .php
    security.limit_extensions = .php .php3 .php4 .php5
    
    ; catch_workers_output = yes
    php_admin_value[error_log] = /var/log/php-fpm/multiphp.error0.log
    php_admin_value[disable_functions] = shell_exec
    
     
    Last edited: Aug 2, 2014
  2. eva2000

    eva2000 Administrator Staff Member

    54,600
    12,225
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,794
    Local Time:
    3:52 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    multiple PHP-FPM pools in action on this very forum :D

    of course I had to manually do this as script didn't exist at the time :)

    [​IMG]
     
  3. rdan

    rdan Well-Known Member

    5,446
    1,408
    113
    May 25, 2014
    Ratings:
    +2,201
    Local Time:
    1:52 PM
    Mainline
    10.2
    I LOVE YOU! :D
     
  4. eva2000

    eva2000 Administrator Staff Member

    54,600
    12,225
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,794
    Local Time:
    3:52 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    I thought you'd like this :)
     
  5. rdan

    rdan Well-Known Member

    5,446
    1,408
    113
    May 25, 2014
    Ratings:
    +2,201
    Local Time:
    1:52 PM
    Mainline
    10.2
    Last edited by a moderator: Aug 2, 2014
  6. eva2000

    eva2000 Administrator Staff Member

    54,600
    12,225
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,794
    Local Time:
    3:52 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
  7. rdan

    rdan Well-Known Member

    5,446
    1,408
    113
    May 25, 2014
    Ratings:
    +2,201
    Local Time:
    1:52 PM
    Mainline
    10.2
    I mean, if you already release that bash script on 1st post, and I can already use multiple pools on my forum maybe it can help ;)
     
  8. eva2000

    eva2000 Administrator Staff Member

    54,600
    12,225
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,794
    Local Time:
    3:52 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Well depending on where the PHP-FPM load is for you, you'd probably still hit the same limits I suspect of which again you'd need to follow advice in my replies at PHP-FPM - WARNING: [pool www] server reached max_children setting (50), consider raising it | Centmin Mod Community to get to the bottom of. Either way, you'll eventually have to do what I outline in that thread - no avoiding it (trial and error tune/testing and log analysis) :) For example, to tune my 8 PHP-FPM pools for this forum, I tried around 80 setting combinations and 200 load test runs on the forum while analysing logs and server stats :)

    From my exclusive for this forum use only multi PHP-FPM pool stats script - emails me reports of the status and state of all PHP-FPM pools for the forums and also reloads PHP-FPM services when PHP-FPM pools become unresponsive (not down as PHP-FPM processes can still be up and running but non-responsive to new connections too).

    Code:
    PHP-FPM pools status: ok
    
    start since avg: 362367.00
    accepted conn avg: 8819.50
    listen queue avg: 21844.38
    max listen avg: 41.12
    listen queue len avg: 65492.00
    idle processes avg: 3.12
    active processes avg: 4.81
    total processes avg: 6.38
    max active processes avg: 6.38
    max children reached avg: 0.00
    slow requests avg: 0.00
    
    ###################################################
    pool:                 www
    process manager:      static
    start time:           27/Jul/2014:16:10:35 +0000
    start since:          362368
    accepted conn:        8605
    listen queue:         0
    max listen queue:     13
    listen queue len:     65492
    idle processes:       3
    active processes:     5
    total processes:      8
    max active processes: 8
    max children reached: 0
    slow requests:        0
    200
    ###################################################
    pool:                 www2
    process manager:      static
    start time:           27/Jul/2014:16:10:35 +0000
    start since:          362368
    accepted conn:        8780
    listen queue:         0
    max listen queue:     59
    listen queue len:     65492
    idle processes:       3
    active processes:     3
    total processes:      6
    max active processes: 6
    max children reached: 0
    slow requests:        0
    200
    ###################################################
    pool:                 www3
    process manager:      static
    start time:           27/Jul/2014:16:10:35 +0000
    start since:          362368
    accepted conn:        8604
    listen queue:         0
    max listen queue:     17
    listen queue len:     65492
    idle processes:       1
    active processes:     5
    total processes:      6
    max active processes: 6
    max children reached: 0
    slow requests:        0
    200
    ###################################################
    pool:                 www4
    process manager:      static
    start time:           27/Jul/2014:16:10:35 +0000
    start since:          362368
    accepted conn:        9607
    listen queue:         0
    max listen queue:     1
    listen queue len:     65492
    idle processes:       5
    active processes:     3
    total processes:      8
    max active processes: 8
    max children reached: 0
    slow requests:        0
    200
    ###################################################
    pool:                 www5
    process manager:      static
    start time:           27/Jul/2014:16:10:35 +0000
    start since:          362368
    accepted conn:        8573
    listen queue:         0
    max listen queue:     101
    listen queue len:     65492
    idle processes:       3
    active processes:     2
    total processes:      5
    max active processes: 5
    max children reached: 0
    slow requests:        0
    200
    ###################################################
    pool:                 www6
    process manager:      static
    start time:           27/Jul/2014:16:10:35 +0000
    start since:          362368
    accepted conn:        8561
    listen queue:         0
    max listen queue:     52
    listen queue len:     65492
    idle processes:       3
    active processes:     3
    total processes:      6
    max active processes: 6
    max children reached: 0
    slow requests:        0
    200
    ###################################################
    pool:                 www7
    process manager:      static
    start time:           27/Jul/2014:16:10:35 +0000
    start since:          362368
    accepted conn:        8623
    listen queue:         0
    max listen queue:     72
    listen queue len:     65492
    idle processes:       3
    active processes:     3
    total processes:      6
    max active processes: 6
    max children reached: 0
    slow requests:        0
    200
    ###################################################
    pool:                 www8
    process manager:      static
    start time:           27/Jul/2014:16:10:35 +0000
    start since:          362368
    accepted conn:        9283
    listen queue:         0
    max listen queue:     14
    listen queue len:     65492
    idle processes:       4
    active processes:     2
    total processes:      6
    max active processes: 6
    max children reached: 0
    slow requests:        0
    200
    When this forum's PHP-FPM loads increase in future, then it's another set of trial and error test/tuning on the books - that's how it is constant monitoring and re-tuning :D ;) That's the weakness of PHP-FPM with Nginx. LiteSpeed Enterprise and OpenLiteSpeed web server's LSAPI PHP implementation scales much better for heavy concurrent non-cached PHP loads.
     
    Last edited: Aug 2, 2014
  9. eva2000

    eva2000 Administrator Staff Member

    54,600
    12,225
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,794
    Local Time:
    3:52 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Roughly got existing multi PHP-FPM pool detection working, I ran the script 2 more times back to end from the first initial run with PHP_POOLS=2. So 2 more script runs should result in a total of 3x2 = 6x PHP-FPM pools created with TCP ports from 9100-9106. Also added DEBUG mode to output some calculations while working it out. Detected existing multi PHP-FPM pools will auto increment both TCP ports and the PHP_POOLS defined value on the fly.

    Code:
    ./phppoolgen.sh
    4 is => 1
    5
    new PHP_POOLS=7
    05
    9105
    multiphp_pools_info_020814-132012.txt
    CHECKRUNPORT is empty: 5
    
    -----------------------------------------------------------------------
    created summary multi PHP-FPM pool info file at:
    /root/tools/multiphp_pools/multiphp_pools_info_020814-133943.txt
    
    Sat Aug 2 13:39:43 UTC 2014
    ####################################
    Summary for php_pool5 pool:
    ####################################
    File location = /usr/local/nginx/conf/phpfpmd/multiphp_pool5.conf
    
    SSH command to view php_pool5 pool stats
    curl --silent --connect-timeout 5 --max-time 5 127.0.0.1/phpstatus_pool5
    
    [php_pool5]
    PHP_PORT=9105
    listen = 127.0.0.1:9105
    ;listen = /tmp/multi_php-fpm5.sock
    slowlog = /var/log/php-fpm/multiphp-slow5.log
    pm.status_path = /phpstatus_pool5
    ping.path = /phpping_pool5
    /var/log/php-fpm/multiphp.error5.log
    
    ####################################
    Summary for php_pool6 pool:
    ####################################
    File location = /usr/local/nginx/conf/phpfpmd/multiphp_pool6.conf
    
    SSH command to view php_pool6 pool stats
    curl --silent --connect-timeout 5 --max-time 5 127.0.0.1/phpstatus_pool6
    
    [php_pool6]
    PHP_PORT=9106
    listen = 127.0.0.1:9106
    ;listen = /tmp/multi_php-fpm6.sock
    slowlog = /var/log/php-fpm/multiphp-slow6.log
    pm.status_path = /phpstatus_pool6
    ping.path = /phpping_pool6
    /var/log/php-fpm/multiphp.error6.log
    
    
    -----------------------------------------------------------------------
    created php status SSH cmds list file at:
    /root/tools/multiphp_pools/multiphp_pools_stats_cmds_020814-133943.txt
    
    curl --silent --connect-timeout 5 --max-time 5 127.0.0.1/phpstatus_pool5
    curl --silent --connect-timeout 5 --max-time 5 127.0.0.1/phpstatus_pool6
    
    -----------------------------------------------------------------------
    created phpstatus config file at:
    /usr/local/nginx/conf/multiphp_status.conf
    
    location ~ ^/(phpstatus_pool0|/phpping_pool0)$ {
        access_log       off;
        #fastcgi_pass    unix:/tmp/multi_php-fpm0.sock;
        fastcgi_pass     127.0.0.1:9100;
        fastcgi_param    SCRIPT_FILENAME ;
        include          fastcgi_params;
        allow  127.0.0.1;
        #allow yourstaticipaddress;
        deny    all;
    }
    
    location ~ ^/(phpstatus_pool1|/phpping_pool1)$ {
        access_log       off;
        #fastcgi_pass    unix:/tmp/multi_php-fpm1.sock;
        fastcgi_pass     127.0.0.1:9101;
        fastcgi_param    SCRIPT_FILENAME ;
        include          fastcgi_params;
        allow  127.0.0.1;
        #allow yourstaticipaddress;
        deny    all;
    }
    
    location ~ ^/(phpstatus_pool3|/phpping_pool3)$ {
        access_log       off;
        #fastcgi_pass    unix:/tmp/multi_php-fpm3.sock;
        fastcgi_pass     127.0.0.1:9103;
        fastcgi_param    SCRIPT_FILENAME ;
        include          fastcgi_params;
        allow  127.0.0.1;
        #allow yourstaticipaddress;
        deny    all;
    }
    
    location ~ ^/(phpstatus_pool4|/phpping_pool4)$ {
        access_log       off;
        #fastcgi_pass    unix:/tmp/multi_php-fpm4.sock;
        fastcgi_pass     127.0.0.1:9104;
        fastcgi_param    SCRIPT_FILENAME ;
        include          fastcgi_params;
        allow  127.0.0.1;
        #allow yourstaticipaddress;
        deny    all;
    }
    
    location ~ ^/(phpstatus_pool5|/phpping_pool5)$ {
        access_log       off;
        #fastcgi_pass    unix:/tmp/multi_php-fpm5.sock;
        fastcgi_pass     127.0.0.1:9105;
        fastcgi_param    SCRIPT_FILENAME ;
        include          fastcgi_params;
        allow  127.0.0.1;
        #allow yourstaticipaddress;
        deny    all;
    }
    
    location ~ ^/(phpstatus_pool6|/phpping_pool6)$ {
        access_log       off;
        #fastcgi_pass    unix:/tmp/multi_php-fpm6.sock;
        fastcgi_pass     127.0.0.1:9106;
        fastcgi_param    SCRIPT_FILENAME ;
        include          fastcgi_params;
        allow  127.0.0.1;
        #allow yourstaticipaddress;
        deny    all;
    }
    
    
    -----------------------------------------------------------------------
    created cleanup_cmds_020814-133943.sh script at:
    /root/tools/multiphp_pools/cleanup_cmds_020814-133943.sh
    
    #!/bin/bash
    rm -rf /usr/local/nginx/conf/multiphp_upstream.conf
    rm -rf /usr/local/nginx/conf/multiphp_status.conf
    #rm -rf /root/tools/multiphp_pools/multiphp_pools_info_020814-133943.txt
    #rm -rf /root/tools/multiphp_pools/multiphp_pools_stats_cmds_020814-133943.txt
    rm -rf /usr/local/nginx/conf/phpfpmd/multiphp_pool5.conf
    rm -rf /var/log/php-fpm/multiphp-slow5.log
    rm -rf /var/log/php-fpm/multiphp.error5.log
    rm -rf /usr/local/nginx/conf/phpfpmd/multiphp_pool6.conf
    rm -rf /var/log/php-fpm/multiphp-slow6.log
    rm -rf /var/log/php-fpm/multiphp.error6.log
    
    -----------------------------------------------------------------------
    created php backup upstream file at:
    /usr/local/nginx/conf/multiphp_upstream.conf
    
    upstream multiphp_backend {
    ip_hash;
    keepalive 16;
    server 127.0.0.1:9105 weight=10 max_fails=5 fail_timeout=10;
    server 127.0.0.1:9106 weight=10 max_fails=5 fail_timeout=10;
    }
    
    -----------------------------------------------------------------------
    created 7 PHP-FPM pool config files
    in directory /usr/local/nginx/conf/phpfpmd/
    total 32K
    drwxr-xr-x 2 root root 4.0K Aug  2 13:39 .
    drwxr-xr-x 5 root root 4.0K Aug  2 13:20 ..
    -rw-r--r-- 1 root root 1.6K Aug  2 13:20 multiphp_pool0.conf
    -rw-r--r-- 1 root root 1.6K Aug  2 13:20 multiphp_pool1.conf
    -rw-r--r-- 1 root root 1.6K Aug  2 13:39 multiphp_pool3.conf
    -rw-r--r-- 1 root root 1.6K Aug  2 13:39 multiphp_pool4.conf
    -rw-r--r-- 1 root root 1.6K Aug  2 13:39 multiphp_pool5.conf
    -rw-r--r-- 1 root root 1.6K Aug  2 13:39 multiphp_pool6.conf
    
    -----------------------------------------------------------------------
    edit /usr/local/nginx/conf/nginx.conf and add include file
    /usr/local/nginx/conf/multiphp_upstream.conf
    
    below and after http {
    
    http {
    include /usr/local/nginx/conf/multiphp_upstream.conf;
    
    
    -----------------------------------------------------------------------
    edit /usr/local/nginx/conf/conf.d/virtual.conf and add include file
    /usr/local/nginx/conf/multiphp_status.conf
    
    below existing include files so looks like
    
    include /usr/local/nginx/conf/staticfiles.conf;
    include /usr/local/nginx/conf/php.conf;
    #include /usr/local/nginx/conf/phpstatus.conf;
    include /usr/local/nginx/conf/drop.conf;
    #include /usr/local/nginx/conf/errorpage.conf;
    include /usr/local/nginx/conf/multiphp_status.conf;
    
    
    
    -----------------------------------------------------------------------
    edit /usr/local/nginx/conf/php.conf include file and change fastcgi_pass
    value 127.0.0.1:9000 to use multiphp_backend defined
    in /usr/local/nginx/conf/multiphp_upstream.conf
    
    fastcgi_pass   127.0.0.1:9000;
    
      becomes
    
    fastcgi_pass   multiphp_backend;
    
    
    -----------------------------------------------------------------------
    edit /usr/local/etc/php-fpm.conf and uncomment this line
    
    from
    
    ;include=/usr/local/nginx/conf/phpfpmd/*.conf
    
    becomes
    
    include=/usr/local/nginx/conf/phpfpmd/*.conf
    
    -----------------------------------------------------------------------
    restart both nginx and php-rpm for changes to take effect
    command shortcut = nprestart
    
    -----------------------------------------------------------------------
    to remove all created multi PHP-FPM pool files and revert to previous
    state, revert change in /usr/local/nginx/conf/php.conf and run cleanup script
    at: /root/tools/multiphp_pools/cleanup_cmds_020814-133943.sh
    
    -----------------------------------------------------------------------
    Detected that existing additional PHP-FPM pools exist
    in /usr/local/nginx/conf/phpfpmd/ directory so you would needed
    to manually adjust /usr/local/nginx/conf/multiphp_upstream.conf
    and /usr/local/nginx/conf/multiphp_status.conf to account
    for those additional multi PHP-FPM pools
    
    You can find previously created multi PHP-FPM pool summary text
    file at /root/tools/multiphp_pools/multiphp_pools_info_*.txt
     
  10. hungphutho

    hungphutho Member

    55
    35
    18
    Jun 2, 2014
    Ratings:
    +35
    Local Time:
    12:52 PM
    1.7.2
    Percona 5.6
    Me that have testing :D
    php_fpm_time-day.png
     
  11. eva2000

    eva2000 Administrator Staff Member

    54,600
    12,225
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,794
    Local Time:
    3:52 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Ah I see you manually setup additional pools :)
     
  12. GhoHan

    GhoHan Member

    33
    14
    8
    Jun 1, 2014
    Ratings:
    +14
    Local Time:
    12:52 PM
    Nginx 1.13.X
    MariaDB 10.1.X
    Multiple PHP-FPM Pools (y)(y)(y)(y)(y)
     
  13. eva2000

    eva2000 Administrator Staff Member

    54,600
    12,225
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,794
    Local Time:
    3:52 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Yes Premium User Members already get early access to above multiple PHP-FPM pool generator script in the private Premium user only forums (other benefits outlined)
     
  14. eva2000

    eva2000 Administrator Staff Member

    54,600
    12,225
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,794
    Local Time:
    3:52 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    It's been a while since I updated phppoolgen.sh multiple php-fpm pool generator so thought I'd give it a whirl.
    Ran phppoolgen.sh which defaults to 2 additional php-fpm pools defined by PHP_POOLS='2' setting.

    • The script first checks in multiple php-fpm pool directory /usr/local/nginx/conf/phpfpmd for any existing multiple php-fpm pools and counts how many additional existing php-fpm pool files exist. If there's existing pools, PHP_POOLS value is incremented by that many number and used as the starting port to increment from for each additional PHP-FPM pool's TCP listen port.
    • So by default Centmin Mod 123.09beta01 defaults to having pre-setup but not enabled, 4 additional pools at /usr/local/nginx/conf/phpfpmd. So the starting port is 1+4 = 5 which is used as a suffix to 91 = 9105 is the starting TCP listen port and incremented by 1 for each additional pool i.e. 9106
    • I updated phppoolgen.sh to default the process manager to ondemand instead of static for the newly created additional php-fpm pools
    Code (Text):
    ./phppoolgen.sh
    4 is => 1
    5
    new PHP_POOLS=7
    05
    9105
    multiphp_pools_info_180618-065053.txt
    CHECKRUNPORT is empty: 5
    
    -----------------------------------------------------------------------
     created summary multi PHP-FPM pool info file at:
     /root/tools/multiphp_pools/multiphp_pools_info_180618-065053.txt
    
    Mon Jun 18 06:50:53 UTC 2018
    ####################################
    Summary for php_pool5 pool:
    ####################################
    File location = /usr/local/nginx/conf/phpfpmd/multiphp_pool5.conf
    
    SSH command to view php_pool5 pool stats
    curl --silent --connect-timeout 5 --max-time 5 127.0.0.1/phpstatus_pool5
    
    [php_pool5]
    PHP_PORT=9105
    listen = 127.0.0.1:9105
    ;listen = /tmp/multi_php-fpm5.sock
    slowlog = /var/log/php-fpm/multiphp-slow5.log
    pm.status_path = /phpstatus_pool5
    ping.path = /phpping_pool5
    /var/log/php-fpm/multiphp.error5.log
    
    ####################################
    Summary for php_pool6 pool:
    ####################################
    File location = /usr/local/nginx/conf/phpfpmd/multiphp_pool6.conf
    
    SSH command to view php_pool6 pool stats
    curl --silent --connect-timeout 5 --max-time 5 127.0.0.1/phpstatus_pool6
    
    [php_pool6]
    PHP_PORT=9106
    listen = 127.0.0.1:9106
    ;listen = /tmp/multi_php-fpm6.sock
    slowlog = /var/log/php-fpm/multiphp-slow6.log
    pm.status_path = /phpstatus_pool6
    ping.path = /phpping_pool6
    /var/log/php-fpm/multiphp.error6.log
    
    
    -----------------------------------------------------------------------
     created php status SSH cmds list file at:
     /root/tools/multiphp_pools/multiphp_pools_stats_cmds_180618-065053.txt
    
    curl --silent --connect-timeout 5 --max-time 5 127.0.0.1/phpstatus_pool5
    curl --silent --connect-timeout 5 --max-time 5 127.0.0.1/phpstatus_pool6
    
    -----------------------------------------------------------------------
     created phpstatus config file at:
     /usr/local/nginx/conf/multiphp_status.conf
    
    location ~ ^/(phpstatus_pool5|/phpping_pool5)$ {
        access_log       off;
        #fastcgi_pass    unix:/tmp/multi_php-fpm5.sock;
        fastcgi_pass     127.0.0.1:9105;
        fastcgi_param    SCRIPT_FILENAME $fastcgi_script_name;
        include          fastcgi_params;
        allow  127.0.0.1;
        #allow yourstaticipaddress;
        deny    all;
    }
    
    location ~ ^/(phpstatus_pool6|/phpping_pool6)$ {
        access_log       off;
        #fastcgi_pass    unix:/tmp/multi_php-fpm6.sock;
        fastcgi_pass     127.0.0.1:9106;
        fastcgi_param    SCRIPT_FILENAME $fastcgi_script_name;
        include          fastcgi_params;
        allow  127.0.0.1;
        #allow yourstaticipaddress;
        deny    all;
    }
    
    
    -----------------------------------------------------------------------
     created cleanup_cmds_180618-065053.sh script at:
     /root/tools/multiphp_pools/cleanup_cmds_180618-065053.sh
    
    #!/bin/bash
    rm -rf /usr/local/nginx/conf/multiphp_upstream.conf
    rm -rf /usr/local/nginx/conf/multiphp_status.conf
    #rm -rf /root/tools/multiphp_pools/multiphp_pools_info_180618-065053.txt
    #rm -rf /root/tools/multiphp_pools/multiphp_pools_stats_cmds_180618-065053.txt
    rm -rf /usr/local/nginx/conf/phpfpmd/multiphp_pool5.conf
    rm -rf /var/log/php-fpm/multiphp-slow5.log
    rm -rf /var/log/php-fpm/multiphp.error5.log
    rm -rf /usr/local/nginx/conf/phpfpmd/multiphp_pool6.conf
    rm -rf /var/log/php-fpm/multiphp-slow6.log
    rm -rf /var/log/php-fpm/multiphp.error6.log
    
    -----------------------------------------------------------------------
     created php backup upstream file at:
     /usr/local/nginx/conf/multiphp_upstream.conf
    
    upstream multiphp_backend {
    ip_hash;
    keepalive 16;
     server 127.0.0.1:9105 weight=10 max_fails=5 fail_timeout=10;
     #server unix:/tmp/multi_php-fpm9105.sock weight=10 max_fails=5 fail_timeout=10;
     server 127.0.0.1:9106 weight=10 max_fails=5 fail_timeout=10;
     #server unix:/tmp/multi_php-fpm9106.sock weight=10 max_fails=5 fail_timeout=10;
    }
    
    -----------------------------------------------------------------------
     created 7 PHP-FPM pool config files
     in directory /usr/local/nginx/conf/phpfpmd/
    total 32K
    drwxr-xr-x 2 root root 4.0K Jun 18 06:50 .
    drwxr-xr-x 6 root root 4.0K Jun 18 06:50 ..
    -rw-r--r-- 1 root root 1.6K Jun 18 06:50 multiphp_pool5.conf
    -rw-r--r-- 1 root root 1.6K Jun 18 06:50 multiphp_pool6.conf
    -rw-r--r-- 1 root root 1.7K Jun  5 00:17 phpfpm_pool2.conf
    -rw-r--r-- 1 root root 1.7K Jun  5 00:17 phpfpm_pool3.conf
    -rw-r--r-- 1 root root 1.7K Jun  5 00:17 phpfpm_pool4.conf
    -rw-r--r-- 1 root root 1.7K Jun  5 00:17 phpfpm_pool5.conf
    
    -----------------------------------------------------------------------
     edit /usr/local/nginx/conf/nginx.conf and add include file
     /usr/local/nginx/conf/multiphp_upstream.conf
    
     below and after http {
    
    http {
    include /usr/local/nginx/conf/multiphp_upstream.conf;
    
    
    -----------------------------------------------------------------------
     edit /usr/local/nginx/conf/conf.d/virtual.conf and add include file
     /usr/local/nginx/conf/multiphp_status.conf
    
     below existing include files so looks like
    
    include /usr/local/nginx/conf/staticfiles.conf;
    include /usr/local/nginx/conf/php.conf;
    #include /usr/local/nginx/conf/phpstatus.conf;
    include /usr/local/nginx/conf/drop.conf;
    #include /usr/local/nginx/conf/errorpage.conf;
    include /usr/local/nginx/conf/multiphp_status.conf;
    
    
    
    -----------------------------------------------------------------------
     edit /usr/local/nginx/conf/php.conf include file and change fastcgi_pass
     value 127.0.0.1:9000 to use multiphp_backend defined
     in /usr/local/nginx/conf/multiphp_upstream.conf
    
     fastcgi_pass   127.0.0.1:9000;
    
      becomes
    
     fastcgi_pass   multiphp_backend;
    
    
    -----------------------------------------------------------------------
     edit /usr/local/etc/php-fpm.conf and uncomment this line
    
     from
    
     ;include=/usr/local/nginx/conf/phpfpmd/*.conf
    
     becomes
    
     include=/usr/local/nginx/conf/phpfpmd/*.conf
    
    -----------------------------------------------------------------------
     restart both nginx and php-rpm for changes to take effect
     command shortcut = nprestart
    
    -----------------------------------------------------------------------
     to remove all created multi PHP-FPM pool files and revert to previous
     state, revert change in /usr/local/nginx/conf/php.conf and run cleanup script
     at: /root/tools/multiphp_pools/cleanup_cmds_180618-065053.sh
    
    -----------------------------------------------------------------------
     Detected that existing additional PHP-FPM pools exist
     in /usr/local/nginx/conf/phpfpmd/ directory so you would needed
     to manually adjust /usr/local/nginx/conf/multiphp_upstream.conf
     and /usr/local/nginx/conf/multiphp_status.conf to account
     for those additional multi PHP-FPM pools
    
     You can find previously created multi PHP-FPM pool summary text
     file at /root/tools/multiphp_pools/multiphp_pools_info_*.txt
    

    The additional pools along with existing 4 php-fpm pools.
    Code (Text):
    ls -lah /usr/local/nginx/conf/phpfpmd
    total 32K
    drwxr-xr-x 2 root root 4.0K Jun 18 06:50 .
    drwxr-xr-x 6 root root 4.0K Jun 18 06:50 ..
    -rw-r--r-- 1 root root 1.6K Jun 18 06:50 multiphp_pool5.conf
    -rw-r--r-- 1 root root 1.6K Jun 18 06:50 multiphp_pool6.conf
    -rw-r--r-- 1 root root 1.7K Jun  5 00:17 phpfpm_pool2.conf
    -rw-r--r-- 1 root root 1.7K Jun  5 00:17 phpfpm_pool3.conf
    -rw-r--r-- 1 root root 1.7K Jun  5 00:17 phpfpm_pool4.conf
    -rw-r--r-- 1 root root 1.7K Jun  5 00:17 phpfpm_pool5.conf
    

    enabling /usr/local/nginx/conf/phpstatus.conf include file in main hostname nginx vhost /usr/local/nginx/conf/conf.d/virtual.conf and edting for php status location context
    Code (Text):
    location ~ ^/(phpstatus_pool5|/phpping_pool5)$ {
        access_log       off;
        #fastcgi_pass    unix:/tmp/multi_php-fpm5.sock;
        fastcgi_pass     127.0.0.1:9105;
        fastcgi_param    SCRIPT_FILENAME $fastcgi_script_name;
        include          fastcgi_params;
        allow  127.0.0.1;
        #allow yourstaticipaddress;
        deny    all;
    }
    
    location ~ ^/(phpstatus_pool6|/phpping_pool6)$ {
        access_log       off;
        #fastcgi_pass    unix:/tmp/multi_php-fpm6.sock;
        fastcgi_pass     127.0.0.1:9106;
        fastcgi_param    SCRIPT_FILENAME $fastcgi_script_name;
        include          fastcgi_params;
        allow  127.0.0.1;
        #allow yourstaticipaddress;
        deny    all;
    }
    

    Code (Text):
    curl --silent --connect-timeout 5 --max-time 5 127.0.0.1/phpstatus_pool5
    pool:                 php_pool5
    process manager:      ondemand
    start time:           18/Jun/2018:07:08:50 +0000
    start since:          9
    accepted conn:        1
    listen queue:         0
    max listen queue:     0
    listen queue len:     128
    idle processes:       0
    active processes:     1
    total processes:      1
    max active processes: 1
    max children reached: 0
    slow requests:        0
    

    Code (Text):
    curl --silent --connect-timeout 5 --max-time 5 127.0.0.1/phpstatus_pool6
    pool:                 php_pool6
    process manager:      ondemand
    start time:           18/Jun/2018:07:08:50 +0000
    start since:          4
    accepted conn:        1
    listen queue:         0
    max listen queue:     0
    listen queue len:     128
    idle processes:       0
    active processes:     1
    total processes:      1
    max active processes: 1
    max children reached: 0
    slow requests:        0
    

    example of created php-fpm pool config /usr/local/nginx/conf/phpfpmd/multiphp_pool5.conf
    Code (Text):
    [php_pool5]
    user = nginx
    group = nginx
    
    listen = 127.0.0.1:9105
    ;listen.allowed_clients = 127.0.0.1
    ;listen.backlog = -1
    listen.backlog = 131072
    
    ;listen = /tmp/multi_php-fpm5.sock
    listen.owner = nginx
    listen.group = nginx
    listen.mode = 0660
    
    pm = ondemand
    pm.max_children = 4
    ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
    pm.start_servers = 8
    pm.min_spare_servers = 4
    pm.max_spare_servers = 12
    pm.max_requests = 4000
    
    rlimit_files = 131072
    rlimit_core = 0
    
    ; The timeout for serving a single request after which the worker process will
    ; be killed. This option should be used when the 'max_execution_time' ini option
    ; does not stop script execution for some reason. A value of '0' means 'off'.
    ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
    ; Default Value: 0
    ;request_terminate_timeout = 0
    ; Default Value: 0
    ;request_slowlog_timeout = 0
    slowlog = /var/log/php-fpm/multiphp-slow5.log
    
    pm.status_path = /phpstatus_pool5
    ping.path = /phpping_pool5
    ping.response = pong
    
    ; Limits the extensions of the main script FPM will allow to parse. This can
    ; prevent configuration mistakes on the web server side. You should only limit
    ; FPM to .php extensions to prevent malicious users to use other extensions to
    ; exectute php code.
    ; Note: set an empty value to allow all extensions.
    ; Default Value: .php
    security.limit_extensions = .php .php3 .php4 .php5
    
    ; catch_workers_output = yes
    php_admin_value[error_log] = /var/log/php-fpm/multiphp.error5.log
    php_admin_value[disable_functions] = shell_exec