Header Ads

Header Ads

Optimizing PHP-FPM



Hi, there!
Now it's time for some php-fpm tips, to optimise it for medium sized projects. Here is an example of configuration pool named www, as standard php-fpm default pool a little bit tuned for performance gain.

[www]
user = www-data
group = www-data
;listen = /run/php/php7.0-fpm.sock
listen = 127.0.0.1:9010
listen.owner = www-data
listen.group = www-data
;listen.mode = 0660
listen.allowed_clients = 127.0.0.1
pm = ondemand
pm.max_children = 15
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 6
pm.process_idle_timeout = 10s;
pm.max_requests = 500
pm.status_path = /status
You can rise some limits, like pm.max_children or pm.start_servers, of course you can tune pm.process_idle_timeout to suit your needs, if the process takes much more time until it's closed, or maybe it have some bugs that avoid it to close at the correct time, maybe it lacks few optimisations at database php layers and so on... If such web apps eats more system memory (RAM) it can overload server, and load averages will rise, and everything will be slow. pm.process_idle_timeout can solve such problem, of course pm = ondemand property will only create children processes when it gets called from web interface. More about php scripts execution timeouts please read here. Also if you are using Nginx along side with php-fpm you can tune it too, here is an example with nginx.conf another one is here and my config file is here:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
        worker_connections 768;
        # multi_accept on;
}
http {
        ##
        # Basic Settings
        ##
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;
        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;
        include /etc/nginx/mime.types;
        default_type application/octet-stream;
        ##
        # SSL Settings
        ##
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;
        ##
        # Logging Settings
        ##
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
        ##
        # Gzip Settings
        ##
        gzip on;
        gzip_disable "msie6";
        ##
        # Virtual Host Configs
        ##
        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}
 You can tune keep_alive_timeout to the smaller value, also types_hash_max_size and of course you can hide server software type and version uncommenting # server_tokens off; value.

No comments:

Copyright (c) 2012-2013 Unix Master. Powered by Blogger.