Tuning of PHP-FPM parameters under large concurrent high load

Source: Internet
Author: User
Tags fpm fast web

Tuning of PHP-FPM parameters under large concurrent high load

Mainly for PHP parameter tuning under Linux


Adjust file descriptor limits


# ulimit-n 1000000

# vi/etc/security/limits.conf

# Setting Shell Limits for File descriptors

* Soft Nofile 1000000

* Hard Nofile 1000000

Prevents file system access time updates for the partition where the PHP code file resides


# Vi/etc/fstab

For example, the PHP code is located in the partition:


/DEV/SDB1 ext4 Errors=remount-ro 0 1

Modified to:


/DEV/SDB1 ext4 Noatime,nodiratime,errors=remount-ro 0 1

Storing temporary files to Tmpfs


(Where to note) when the site has to handle a large number of small image uploads, using the memory file system TMPFS to store, you can reduce the cost of some I/O. However, if the user is uploading very large files (such as video), it is not appropriate to use TMPFS.


# Vi/etc/fstab

Tmpfs/tmp Tmpfs defaults,nosuid,noatime 0 0



PHP.ini Configuration Tuning


# VI Php-app.ini

[PHP]

Engine = On

expose_php = Off


Max_execution_time = 5

Memory_limit = 256M

error_reporting = E_all & ~e_deprecated

Display_errors = Off

Display_startup_errors = Off

Html_errors = Off

Default_socket_timeout = 5


File_uploads = On

Upload_tmp_dir =/tmp/php

Upload_max_filesize = 50M

Post_max_size = 50M

Max_file_uploads = 20


Date.timezone = ' Asia/shanghai '

Note that this setting max_execution_time only 5 seconds. For a fast web app, we really don't want any long-running Web requests in the Web app, A Web request that lasts more than 5 seconds usually means something is wrong. Our goal is to page responses within 300-500MS.


PHP-FPM Configuration Tuning

# VI Php-fpm.conf

[My_app]

; FASTCGI/PHP-FPM using UNIX Sockets

Listen =/data/my_app/tmp/php.sock

Listen.backlog = 300

user = www

Group = www

PM = dynamic

; Estimated Pm.max_children = (MAX_MEMORY-500MB)/20MB

Pm.max_children = 100

Recommended for the largest Pm.max_children%10

Pm.start_servers = 10

Pm.min_spare_servers = 5

Pm.max_spare_servers = 15

pm.max_requests = 1000

Pm.status_path =/php_status


Request_terminate_timeout = 0

Request_slowlog_timeout = 0

Slowlog =/data/my_app/logs/slow.log

The above is the summary of these parameters

Tuning of PHP-FPM parameters under large concurrent high load

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.