linux - (solved) PHP-FPM with nginx config (too many process) -


i using php-fpm along nginx. fine. site stops lot of time in day. have tried changing no of child process count in config file. there no luck.

when try run "top" command in console see there lots of php fpm processes. there solution left restart fpm. bad site reputation. can please figure out going wrong on side.

enter image description here

here www.conf file

    ; start new pool named 'www'. [www]  ; address on accept fastcgi requests. ; valid syntaxes are: ;   'ip.add.re.ss:port'    - listen on tcp socket specific address on ;                            specific port; ;   'port'                 - listen on tcp socket addresses on ;                            specific port; ;   '/path/to/unix/socket' - listen on unix socket. ; note: value mandatory. listen = 127.0.0.1:9000  ; set listen(2) backlog. value of '-1' means unlimited. ; default value: -1 ;listen.backlog = -1  ; list of ipv4 addresses of fastcgi clients allowed connect. ; equivalent fcgi_web_server_addrs environment variable in original ; php fcgi (5.2.2+). makes sense tcp listening socket. each address ; must separated comma. if value left blank, connections ; accepted ip address. ; default value: listen.allowed_clients = 127.0.0.1  ; set permissions unix socket, if 1 used. in linux, read/write ; permissions must set in order allow connections web server. many ; bsd-derived systems allow connections regardless of permissions.  ; default values: user , group set running user ;                 mode set 0666 ;listen.owner = nobody ;listen.group = nobody ;listen.mode = 0666  ; unix user/group of processes ; note: user mandatory. if group not set, default user's group ;       used. ; rpm: apache choosed able access dir httpd user = ec2-user ; rpm: keep group allowed write in log dir. group = ec2-user  ; choose how process manager control number of child processes. ; possible values: ;   static  - fixed number (pm.max_children) of child processes; ;   dynamic - number of child processes set dynamically based on ;             following directives: ;             pm.max_children      - maximum number of children can ;                                    alive @ same time. ;             pm.start_servers     - number of children created on startup. ;             pm.min_spare_servers - minimum number of children in 'idle' ;                                    state (waiting process). if number ;                                    of 'idle' processes less ;                                    number children created. ;             pm.max_spare_servers - maximum number of children in 'idle' ;                                    state (waiting process). if number ;                                    of 'idle' processes greater ;                                    number children killed. ; note: value mandatory. pm = ondemand pm.process_idle_timeout = 40s; ; number of child processes created when pm set 'static' , ; maximum number of child processes created when pm set 'dynamic'. ; value sets limit on number of simultaneous requests ; served. equivalent apachemaxclients directive mpm_prefork. ; equivalent php_fcgi_children environment variable in original php ; cgi. ; note: used when pm set either 'static' or 'dynamic' ; note: value mandatory. pm.max_children = 50  ; number of child processes created on startup. ; note: used when pm set 'dynamic' ; default value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2 pm.start_servers = 5  ; desired minimum number of idle server processes. ; note: used when pm set 'dynamic' ; note: mandatory when pm set 'dynamic' pm.min_spare_servers = 5  ; desired maximum number of idle server processes. ; note: used when pm set 'dynamic' ; note: mandatory when pm set 'dynamic' pm.max_spare_servers = 35  ; number of requests each child process should execute before respawning. ; can useful work around memory leaks in 3rd party libraries. ; endless request processing specify '0'. equivalent php_fcgi_max_requests. ; default value: 0 ;pm.max_requests = 500  ; uri view fpm status page. if value not set, no uri ; recognized status page. default, status page shows following ; information: ;   accepted conn    - number of request accepted pool; ;   pool             - name of pool; ;   process manager  - static or dynamic; ;   idle processes   - number of idle processes; ;   active processes - number of active processes; ;   total processes  - number of idle + active processes. ; values of 'idle processes', 'active processes' , 'total processes' ; updated each second. value of 'accepted conn' updated in real time. ; example output: ;   accepted conn:   12073 ;   pool:             www ;   process manager:  static ;   idle processes:   35 ;   active processes: 65 ;   total processes:  100 ; default status page output formatted text/plain. passing either ; 'html' or 'json' query string return corresponding output ; syntax. example: ;   http://www.foo.bar/status ;   http://www.foo.bar/status?json ;   http://www.foo.bar/status?html ; note: value must start leading slash (/). value can ;       anything, may not idea use .php extension or ;       may conflict real php file. ; default value: not set  ;pm.status_path = /status  ; ping uri call monitoring page of fpm. if value not set, no ; uri recognized ping page. used test outside ; fpm alive , responding, or ; - create graph of fpm availability (rrd or such); ; - remove server group if not responding (load balancing); ; - trigger alerts operating team (24/7). ; note: value must start leading slash (/). value can ;       anything, may not idea use .php extension or ;       may conflict real php file. ; default value: not set ;ping.path = /ping  ; directive may used customize response of ping request. ; response formatted text/plain 200 response code. ; default value: pong ;ping.response = pong  ; timeout serving single request after worker process ; killed. option should used when 'max_execution_time' ini option ; not stop script execution reason. value of '0' means 'off'. ; available units: s(econds)(default), m(inutes), h(ours), or d(ays) ; default value: 0 ;request_terminate_timeout = 0  ; timeout serving single request after php backtrace ; dumped 'slowlog' file. value of '0s' means 'off'. ; available units: s(econds)(default), m(inutes), h(ours), or d(ays) ; default value: 0 ;request_slowlog_timeout = 0  ; log file slow requests ; default value: not set ; note: slowlog mandatory if request_slowlog_timeout set slowlog = /var/log/php-fpm/www-slow.log  ; set open file descriptor rlimit. ; default value: system defined value ;rlimit_files = 1024  ; set max core size rlimit. ; possible values: 'unlimited' or integer greater or equal 0 ; default value: system defined value ;rlimit_core = 0  ; chroot directory @ start. value must defined ; absolute path. when value not set, chroot not used. ; note: chrooting great security feature , should used whenever  ;       possible. however, php paths relative chroot ;       (error_log, sessions.save_path, ...). ; default value: not set ;chroot =   ; chdir directory @ start. value must absolute path. ; default value: current directory or / when chroot ;chdir = /var/www  ; redirect worker stdout , stderr main error log. if not set, stdout , ; stderr redirected /dev/null according fastcgi specs. ; default value: no ;catch_workers_output = yes  ; limits extensions of main script fpm allow parse. can ; prevent configuration mistakes on web server side. should limit ; fpm .php extensions prevent malicious users use other extensions ; exectute php code. ; note: set empty value allow extensions. ; default value: .php ;security.limit_extensions = .php .php3 .php4 .php5  ; pass environment variables ld_library_path. $variables taken ; current environment. ; default value: clean env ;env[hostname] = $hostname ;env[path] = /usr/local/bin:/usr/bin:/bin ;env[tmp] = /tmp ;env[tmpdir] = /tmp ;env[temp] = /tmp  ; additional php.ini defines, specific pool of workers. these settings ; overwrite values defined in php.ini. directives ; same php sapi: ;   php_value/php_flag             - can set classic ini defines can ;                                    overwritten php call 'ini_set'.  ;   php_admin_value/php_admin_flag - these directives won't overwritten ;                                     php call 'ini_set' ; php_*flag, valid values on, off, 1, 0, true, false, yes or no.  ; defining 'extension' load corresponding shared extension ; extension_dir. defining 'disable_functions' or 'disable_classes' not ; overwrite defined php.ini values, append new value ; instead.  ; default value: nothing defined default except values in php.ini , ;                specified @ startup -d argument ;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com ;php_flag[display_errors] = off php_admin_value[error_log] = /var/log/php-fpm/www-error.log php_admin_flag[log_errors] = on ;php_admin_value[memory_limit] = 32m 

and php-fpm.conf is

    ;;;;;;;;;;;;;;;;;;;;; ; fpm configuration ; ;;;;;;;;;;;;;;;;;;;;;  ; relative paths in configuration file relative php's install ; prefix.  ; include 1 or more files. if glob(3) exists, used include bunch of ; files glob(3) pattern. directive can used everywhere in ; file. include=/etc/php-fpm.d/*.conf  ;;;;;;;;;;;;;;;;;; ; global options ; ;;;;;;;;;;;;;;;;;;  [global] ; pid file ; default value: none pid = /var/run/php-fpm/php-fpm.pid  ; error log file ; default value: /var/log/php-fpm.log error_log = /var/log/php-fpm/error.log  ; log level ; possible values: alert, error, warning, notice, debug ; default value: notice ;log_level = notice  ; if number of child processes exit sigsegv or sigbus within time ; interval set emergency_restart_interval fpm restart. value ; of '0' means 'off'. ; default value: 0 emergency_restart_threshold = 3  ; interval of time used emergency_restart_interval determine when  ; graceful restart initiated.  can useful work around ; accidental corruptions in accelerator's shared memory. ; available units: s(econds), m(inutes), h(ours), or d(ays) ; default unit: seconds ; default value: 0 emergency_restart_interval = 1m  ; time limit child processes wait reaction on signals master. ; available units: s(econds), m(inutes), h(ours), or d(ays) ; default unit: seconds ; default value: 0 process_control_timeout = 10  ; send fpm background. set 'no' keep fpm in foreground debugging. ; default value: yes ;daemonize = yes  ;;;;;;;;;;;;;;;;;;;; ; pool definitions ;  ;;;;;;;;;;;;;;;;;;;;  ; see /etc/php-fpm.d/*.conf 

i found reason behind issue. when checked aws console. showing cpu usage graph getting peek value after each 3 hrs. checked crons , found there cron upload videos youtube. cron used create multiple process each video upload avoid script timeout situation. in script have fetch video server. main reason this. streamname providing fetch video server resulted in continues waiting state. due php-fpm starts waiting script exit. hence unresolved state occurred every 3 hrs.

so if guys getting same error shown in above screenshot check time when cpu system getting peek value , try figure out what's running @ time. there must in php script responsible php-fpm wait endlessly.

if php-fpm started should stop if not try improve code.

i think have got main idea. try find if found same in case , server running smoothly.

cheers :)


Comments