Tech Tips

  1. プログラミング
  2. 304 view

[php5-fpm] php5-fpm を使用していて急にサイトが重くなった場合に確認すること

Contents

概要

Nginx+php5-fpm+Wordpressの構成で、
ある日突然URLを叩いたら500エラーが返ってくる用になったため、
ログを見たら以下のようになっていた。
..... [error] 846#0: *1650149 upstream timed out (110: Connection timed out) while reading response header from upstream .....
php5-fpmの設定を変更したら直ったのでそのメモ。

OS

Linux www3241up 3.2.0-58-generic #88-Ubuntu SMP Tue Dec 3 17:37:58 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

手順

1. topやhtopコマンドでプロセス状況を確認する。

php5fpm1

mysqlのプロセスが多いようだ。
これが原因な気がする。

2. php5-fpmのプロセス設定をする。

$ sudo vim /etc/php5/fpm/pool.d/www.conf
; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI. The below defaults are based on a server without much resources. Don't
; forget to tweak pm.* to fit your needs.
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
; Note: This value is mandatory.
pm.max_children = 5

; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 1

; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 1

; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 2
このようにプロセス数に関する部分を低く設定する。

3. php5-fpmを再起動する。

$ sudo /etc/init.d/php5-fpm restart
これで速くなった。

プログラミングの最近記事

  1. PlatformIO IDE for VSCode を使用して VSCode で Ardu…

  2. ROS Docker イメージで発生した GPG error の解消方法

  3. Streamlit で訪れた国を色づけした世界地図を作成できるアプリケーションを作成してみ…

  4. M5Stack Core2 for AWS – ESP32 IoT開発キットで…

  5. D3.js v7 で点・線・テキスト・ツールチップ・ズームを設定する方法

PAGE TOP