[Linux host] optimize your PHP-FPM (php5.3+) to make your website run faster

Source: Internet
Author: User
Tags http 200 dedicated server

Since php5.3 PHP comes with PHP-FPM is not the same as php5.2 in the form of plugins exist. This brings us a benefit. 502 is not so easy to show up.
The vast majority of Linux in the jar should still be in the lnmp of the small army, but the configuration optimization is unsatisfactory.
Configuration file location for PHP-FPM:
/usr/local/php/etc/php-fpm.conf
PID = Run/php-fpm.pid
PID settings, default in the installation directory of Var/run/php-fpm.pid, it is recommended to open
Error_log = Log/php-fpm.log
Error log, default in the installation directory of Var/log/php-fpm.log
Log_level = Notice
The error level. The available levels are: alert (which must be processed immediately), error (Error condition), warning (warning condition), notice (general important information), debug (debug information). Default: Notice.
Emergency_restart_threshold = 60
Emergency_restart_interval = 60s
The emergency_restart_threshold will gracefully restart if the number of php-cgi processes that have SIGSEGV or sigbus errors within the values set by Emergency_restart_interval is more than PHP-FPM. These two options generally leave the default values.
Process_control_timeout = 0
Sets the time-out period for the child process to accept the primary process multiplexing signal. Available units: s (seconds), M (min), H (Hours), or D (day) default units: s (seconds). Default value: 0.
Daemonize = yes
The background performs FPM, and the default value is yes, if you want to change to no for debugging.
In FPM, you can use different settings to run multiple process pools. These settings can be set individually for each process pool.
Listen = 127.0.0.1:9000
The FPM listener port, which is the address of the PHP processing in Nginx, is usually the default value.
The available formats are: ' Ip:port ', ' Port ', '/path/to/unix/socket '. Each process pool needs to be set.
Listen.backlog =-1
Backlog number, 1 means no limit, determined by the operating system, this line comments off. Backlog meaning reference:
Listen.allowed_clients = 127.0.0.1
Allow access to the IP of the fastcgi process, set any to unlimited IP, if you want to set other hosts Nginx can also access this FPM process, listen to set the cost of the IP can be accessed. The default value is any.
Each address is separated by commas. Allows any server to request a connection if it is not set or is empty
Listen.owner = www
Listen.group = www
Listen.mode = 0666
UNIX socket Settings option, if you use TCP access, comment here.
user = www
Group = www
Start the account and group for the process
PM = dynamic
PM means using that way, there are two values to choose from, that is, static mode, or dynamic (called Apache-like but not good at the time of Dynamics Mode 5.2)
If Static is selected, the number of fixed child processes is specified by Pm.max_children.
If dynamic is selected, it is determined by the following argument:
Pm.max_children, maximum number of child processes
Pm.start_servers, number of processes at startup
Pm.min_spare_servers, the minimum number of idle processes is guaranteed, and if the idle process is less than this value, a new child process is created
Pm.max_spare_servers, the maximum number of idle processes is guaranteed, and if the idle process is greater than this value, the cleanup
For a dedicated server, the PM can be set to static.
pm.max_requests = 1000
Sets the number of requests for the service before each child process is reborn. is useful for third-party modules that may have a memory leak. If set to ' 0′, the request is always accepted. Equivalent to the PHP_FCGI_MAX_REQUESTS environment variable. Default value: 0.
Pm.status_path =/status
The URL of the FPM status page. If not set, the status page cannot be accessed. Default value: None.
Ping.path =/ping
The ping URL of the FPM monitoring page. If not set, the ping page cannot be accessed. This page is used to externally detect whether FPM is alive and can respond to requests. Note that you must start with a slash (/).
Ping.response = Pong
Used to define the return of the ping request accordingly. Returns the Text/plain format text for HTTP 200. Default value: Pong.
Request_terminate_timeout = 0
Sets the time-out for a single request to abort. This option may be useful for scripts in php.ini settings where ' Max_execution_time ' is not aborted for some special reason. Set to ' 0′ ' to indicate ' Off '.
You can try changing this option when a 502 error occurs frequently.
Request_slowlog_timeout = 10s
When a request for this setting time-out expires, the corresponding PHP call stack information is written to the slow log. Set to ' 0′ ' means ' Off '
Slowlog = log/$pool. Log.slow
Slow-Request logging, with Request_slowlog_timeout
Rlimit_files = 1024
Sets the Rlimit limit for the file open descriptor. Default value: System-defined Value
System default open handle is 1024, can use Ulimit-n view, ulimit-n 2048 modify.
Rlimit_core = 0
Sets the maximum limit value for the core rlimit. Available values: ' Unlimited ', 0, or positive integer. Default value: System-defined value.
Chroot =
The Chroot directory at startup. The defined directory needs to be an absolute path. If not set, Chroot is not used.
ChDir =
Sets the startup directory, which is automatically chdir to the directory when it starts. The defined directory needs to be an absolute path. Default value: Current directory, or/directory (chroot)
Catch_workers_output = yes
REDIRECT StdOut and stderr to the primary error log file during the run. If not set, stdout and stderr will be redirected to/dev/null according to the FASTCGI rules. Default value: Empty
Here is an example of my PHP configuration:
[Global]pid =/usr/local/php/var/run/php-fpm.pid
Error_log =/home/wwwlogs/php-fpm.log
Log_level = Notice
Rlimit_files = 65535
Rlimit_core = 0
[WWW]
Listen =/tmp/php-cgi.sock
user =NobodyNginx, PHP-FPM process permissions cannot be run with site ownership security issues
Group =NobodyNginx, PHP-FPMProcesspermissions cannot be run with site ownership security issues
PM = dynamic
Pm.max_children = 36 Number of static mode open processes
Pm.start_servers = 9 Dynamic mode default number of open processes
Pm.min_spare_servers = 8 Dynamic Mode default minimum number of reserved processes
Pm.max_spare_servers = 36 Dynamic mode default maximum number of processes specifically via Netstat-napo |grep "PHP-FPM" | Wc-l and system Load determination
Pm.max_requests = 4096 process performs XXX after restart freeing memory to avoid memory leaks
Request_terminate_timeout = 100 process Time-out
request_slowlog_timeout = 3s record php execution command greater than 3 seconds
Slowlog =/home/wwwlogs/php-fpm.log.slow
Rlimit_files = 65535 This value must be changed to the default is too small to change the log will have an error but the same as the number of global files to view the ULIMIT-N system global Settings
Rlimit_core = 0------------------------------------------------------------------------------------------------- ----------[global]pid =/usr/local/php/var/run/php-fpm.piderror_log =/home/wwwlogs/php-fpm.loglog_level = Noticerlimit_files = 65535rlimit_core = 0 [www]listen =/tmp/php-cgi.sockuser = Nobodygroup = NOBODYPM = Dynamticpm.max_ch Ildren = 20pm.start_servers = 2pm.min_spare_servers = 1pm.max_spare_servers = 20pm.max_requests = 4096request_slowlog_ Timeout = 3sslowlog =/home/wwwlogs/php-fpm.log.slow Request_terminate_timeout = 100rlimit_files = 65535rlimit_core = 0

[Linux host] optimize your PHP-FPM (php5.3+) to make your website run faster

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.