PHP-FPM pool, php slow execution log, Open_basedir, PHP-FPM process Management

Source: Internet
Author: User
Tags deprecated fpm

The pool of PHP-FPM
  • To avoid using the same pool for multiple sites, a separate pool for each site needs to be configured if one site's traffic is too large to cause problems with resource exhaustion, which in turn affects the normal operation of other sites using the same pool. The way of implementation and Nginx Vhost almost
  • Edit the master configuration file
    [[email protected] aming.com]# vim /usr/local/php-fpm/etc/php-fpm.conf[global]pid = /usr/local/php-fpm/var/run/php-fpm.piderror_log = /usr/local/php-fpm/var/log/php-fpm.loginclude = etc/php-fpm.d/*.conf
  • Rebuilding multiple Pool
    [[email protected] aming.com]# mkdir/usr/local/php-fpm/etc/php-fpm.d[[email protected] aming.com]# CD!$ Cd/usr/local/php-fpm/etc/php-fpm.d[[email protected] php-fpm.d]# Vim www.conf[www]listen =/tmp/php-fcgi.sock# Listen = 127.0.0.1:9000listen.mode = 666user = Php-fpmgroup = PHP-FPMPM = Dynamicpm.max_children = 50pm.start_servers = 20 Pm.min_spare_servers = 5pm.max_spare_servers = 35pm.max_requests = 500rlimit_files = 1024x768 [[email protected] Php-fp m.d]# Vim Aming.conf[aming]listen =/tmp/aming.sock#listen = 127.0.0.1:9000listen.mode = 666user = Php-fpmgroup = PHP-FPMP m = Dynamicpm.max_children = 50pm.start_servers = 20pm.min_spare_servers = 5pm.max_spare_servers = 35pm.max_requests = 500 Rlimit_files = 1024[[email protected] php-fpm.d]#/usr/local/php-fpm/sbin/php-fpm-t[18-jun-2018 23:31:06] Notice:configuration file/usr/local/php-fpm/etc/php-fpm.conf test is successful[[email protected] php-fpm.d]#/ ETC/INIT.D/PHP-FPM restartgracefully shutting down pHP-FPM. Donestarting PHP-FPM Done
  • View
    [[email protected] php-fpm.d]# PS aux |grep php-fpmroot 5306 0.2 0.2 227292 4984?        Ss 23:31 0:00 php-fpm:master process (/usr/local/php-fpm/etc/php-fpm.conf) php-fpm 5307 0.0 0.2 227232 4724?        S 23:31 0:00 php-fpm:pool amingphp-fpm 5308 0.0 0.2 227232 4724?        S 23:31 0:00 php-fpm:pool amingphp-fpm 5309 0.0 0.2 227232 4724?        S 23:31 0:00 php-fpm:pool amingphp-fpm 5310 0.0 0.2 227232 4724?        S 23:31 0:00 php-fpm:pool amingphp-fpm 5311 0.0 0.2 227232 4728?        S 23:31 0:00 php-fpm:pool amingphp-fpm 5312 0.0 0.2 227232 4728?        S 23:31 0:00 php-fpm:pool amingphp-fpm 5313 0.0 0.2 227232 4728?        S 23:31 0:00 php-fpm:pool amingphp-fpm 5314 0.0 0.2 227232 4728?        S 23:31 0:00 php-fpm:pool amingphp-fpm 5315 0.0 0.2 227232 4728?        S 23:31 0:00 php-fpm:pool amingphp-fpm 5316 0.0 0.2 227232 4728? S 23:31 0:XX php-fpm:pool amingphp-fpm 5317 0.0 0.2 227232 4728?        S 23:31 0:00 php-fpm:pool amingphp-fpm 5318 0.0 0.2 227232 4728?        S 23:31 0:00 php-fpm:pool amingphp-fpm 5319 0.0 0.2 227232 4728?        S 23:31 0:00 php-fpm:pool amingphp-fpm 5320 0.0 0.2 227232 4728?        S 23:31 0:00 php-fpm:pool amingphp-fpm 5321 0.0 0.2 227232 4732?        S 23:31 0:00 php-fpm:pool amingphp-fpm 5322 0.0 0.2 227232 4732?        S 23:31 0:00 php-fpm:pool amingphp-fpm 5323 0.0 0.2 227232 4732?        S 23:31 0:00 php-fpm:pool amingphp-fpm 5324 0.0 0.2 227232 4732?        S 23:31 0:00 php-fpm:pool amingphp-fpm 5325 0.0 0.2 227232 4732?        S 23:31 0:00 php-fpm:pool amingphp-fpm 5326 0.0 0.2 227232 4732?        S 23:31 0:00 php-fpm:pool amingphp-fpm 5327 0.0 0.2 227232 4728?        S 23:31 0:00 php-fpm:pool wwwphp-fpm 5328 0.0 0.2 227232 4728? S 23:31 0:00 php-fpm:pool wwwphp-fpm 5329 0.0 0.2 227232 4728?        S 23:31 0:00 php-fpm:pool wwwphp-fpm 5330 0.0 0.2 227232 4728?        S 23:31 0:00 php-fpm:pool wwwphp-fpm 5331 0.0 0.2 227232 4732?        S 23:31 0:00 php-fpm:pool wwwphp-fpm 5332 0.0 0.2 227232 4732?        S 23:31 0:00 php-fpm:pool wwwphp-fpm 5333 0.0 0.2 227232 4732?        S 23:31 0:00 php-fpm:pool wwwphp-fpm 5334 0.0 0.2 227232 4732?        S 23:31 0:00 php-fpm:pool wwwphp-fpm 5335 0.0 0.2 227232 4732?        S 23:31 0:00 php-fpm:pool wwwphp-fpm 5336 0.0 0.2 227232 4732?        S 23:31 0:00 php-fpm:pool wwwphp-fpm 5337 0.0 0.2 227232 4736?        S 23:31 0:00 php-fpm:pool wwwphp-fpm 5338 0.0 0.2 227232 4736?        S 23:31 0:00 php-fpm:pool wwwphp-fpm 5339 0.0 0.2 227232 4736?        S 23:31 0:00 php-fpm:pool wwwphp-fpm 5340 0.0 0.2 227232 4736? S 23:31 0:00 php-fpm: Pool wwwphp-fpm 5341 0.0 0.2 227232 4736?        S 23:31 0:00 php-fpm:pool wwwphp-fpm 5342 0.0 0.2 227232 4736?        S 23:31 0:00 php-fpm:pool wwwphp-fpm 5343 0.0 0.2 227232 4736?        S 23:31 0:00 php-fpm:pool wwwphp-fpm 5344 0.0 0.2 227232 4736?        S 23:31 0:00 php-fpm:pool wwwphp-fpm 5345 0.0 0.2 227232 4736?        S 23:31 0:00 php-fpm:pool wwwphp-fpm 5346 0.0 0.2 227232 4736? S 23:31 0:00 php-fpm:pool wwwroot 5350 0.0 0.0 112680 984 pts/1 s+ 23:32 0:00 grep--color=auto php- Fpm
    PHP Slow Execution log
  • Add the following two lines to the configuration file
    [[email protected] ~]# vim /usr/local/php-fpm/etc/php-fpm.d/www.confrequest_slowlog_timeout = 1#当请求超过1秒开始记录日志slowlog = /usr/local/php-fpm/var/log/www-slow.log#日志存放地址
  • Test
    [[email protected] ~]# vim /data/wwwroot/test.com/sleep.php<?phpecho "test slow log";sleep(2);echo "done";?>[[email protected] ~]# curl -x127.0.0.1:80 test.com/sleep.phptest slow logdone[[email protected] ~]# cat /usr/local/php-fpm/var/log/www-slow.log [19-Jun-2018 08:58:20]  [pool www] pid 1451script_filename = /data/wwwroot/test.com/sleep.php[0x00007f4cadc922e0] sleep() /data/wwwroot/test.com/sleep.php:3
    Open_basedir
  • When a server runs multiple sites, you can use the openBasedir to limit the range of directories on the servers that each site can access, and you need to set open basedir per pool
    [[email protected] ~]# vim /usr/local/php-fpm/etc/php-fpm.d/www.confphp_admin_value[open_basedir]=/data/wwwroot/eetest.com:/tmp/#故意写错/data/wwwroot/eetest.com,正确是/data/wwwroot/test.com
  • To test
    [[email protected] ~]# curl -x127.0.0.1:80 test.com/sleep.php -IHTTP/1.1 404 Not FoundServer: nginx/1.14.0Date: Tue, 19 Jun 2018 01:21:13 GMTContent-Type: text/html; charset=UTF-8Connection: keep-aliveX-Powered-By: PHP/5.6.30
  • Change www.conf again, modify the path, test again
    [[email protected] ~]# vim /usr/local/php-fpm/etc/php-fpm.d/www.conf [[email protected] ~]# /etc/init.d/php-fpm restartGracefully shutting down php-fpm . doneStarting php-fpm  done[[email protected] ~]# curl -x127.0.0.1:80 test.com/sleep.phptest slow logdone
  • Configuration error Log
    [[email protected] ~]# vim /usr/local/php-fpm/etc/php.inierror_reporting = E_ALLdisplay_errors = Off;error_log = syslogerror_log = /usr/local/php-fpm/var/log/php_errors.log[[email protected] ~]# touch /usr/local/php-fpm/var/log/php_errors.log[[email protected] ~]# chmod 777 /usr/local/php-fpm/var/log/php_errors.log[[email protected] ~]# /etc/init.d/php-fpm restartGracefully shutting down php-fpm . doneStarting php-fpm  done
  • Test again, deliberately wrong before testing
    [[email protected] ~]# vim /usr/local/php-fpm/etc/php-fpm.d/www.confphp_admin_value[open_basedir]=/data/wwwroot/eetest.com:/tmp/#故意写错/data/wwwroot/eetest.com,正确是/data/wwwroot/test.com
    [[email protected] ~]# curl -x127.0.0.1:80 test.com/sleep.php -IHTTP/1.1 404 Not FoundServer: nginx/1.14.0Date: Tue, 19 Jun 2018 01:34:14 GMTContent-Type: text/html; charset=UTF-8Connection: keep-aliveX-Powered-By: PHP/5.6.30
  • View Logs
    [[email protected] ~]# cat /usr/local/php-fpm/var/log/php_errors.log[19-Jun-2018 01:32:53 UTC] PHP Deprecated:  Comments starting with ‘#‘ are deprecated in Unknown on line 1 in Unknown on line 0[19-Jun-2018 01:32:53 UTC] PHP Deprecated:  Comments starting with ‘#‘ are deprecated in Unknown on line 1 in Unknown on line 0[19-Jun-2018 01:34:14 UTC] PHP Warning:  Unknown: open_basedir restriction in effect. File(/data/wwwroot/test.com/sleep.php) is not within the allowed path(s): (/data/wwwroot/eetest.com:/tmp/) in Unknown on line 0[19-Jun-2018 01:34:14 UTC] PHP Warning:  Unknown: failed to open stream: Operation not permitted in Unknown on line 0
    PHP-FPM Process Management
    [[email protected] ~]# cat /usr/local/php-fpm/etc/php-fpm.d/www.conf[www]listen = /tmp/www.sock;listen = 127.0.0.1:9000listen.mode = 666user = php-fpmgroup = php-fpmpm = dynamicpm.max_children = 50pm.start_servers = 20pm.min_spare_servers = 5pm.max_spare_servers = 35pm.max_requests = 500rlimit_files = 1024 request_slowlog_timeout = 1slowlog = /usr/local/php-fpm/var/log/www-slow.logphp_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/
  • PM = dynamic process management, or static, when the following configuration does not take effect, the 50 child processes are generated without changing
  • Pm.max_children = 50//maximum number of sub-processes, PS aux can be viewed
  • Pm.start_servers = 20//Number of processes that will start when the service is started
  • Pm.min_spare_servers = 5//Defines the minimum number of child processes in the idle period, and if this value is reached, the PHP-FPM service automatically derives the new child process.
  • Pm.max_spare_servers = 35//Defines the maximum number of child processes in the idle period, or, if higher than this value, to start cleaning up idle child processes.
  • Pm.max_requests = 500//defines the maximum number of requests processed by a child process, that is, in a PHP-FPM child process can handle so many requests, when this value is reached, it automatically exits

PHP-FPM pool, php slow execution log, Open_basedir, PHP-FPM process management

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.