8
11

More than 5 years have passed since last update.

php-fpm の reload は実行中の worker がおなくなりになる

Last updated at Posted at 2015-03-30

背景

処理中の worker を影響を与えずに、ログレベルを debug にしたかった

環境

Ubuntu 14.10 + php5-fpm 5.5.12

man

PHP-FPM(8)                                                          Scripting Language


SIGNAL
       Once started, php-fpm then responds to several POSIX signals:

              SIGINT,SIGTERM      immediate termination
              SIGQUIT             graceful stop
              SIGUSR1             re-open log file
              SIGUSR2             graceful reload of all workers + reload of fpm conf/binary

SIGUSR2 で大丈夫そうですね。

init script

/etc/init.d/php5-fpm の中身

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
        #
        # If the daemon can reload its configuration without
        # restarting (for example, when it is sent a SIGHUP),
        # then implement that here.
        #
        start-stop-daemon --stop --signal USR2 --quiet --pidfile $PIDFILE --name $NAME
        return 0
}

USR2、想定どおりですね。

動作確認

/sleep.php をこしらえる

<?php
sleep(100);

そして、

curl http://127.0.0.1/sleep.php

を叩いて、別の console で

kill -USR2 $(/usr/local/bin/supervisorctl pid php5-fpm)

をたたく。期待するのは curl がずっとレスポンス待ちであること。

が、

<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx</center>
</body>
</html>

おっと、 worker がおなくなりになりました。。。

追記

もう少し調べてみると、 Bug #60961: Graceful Restart (USR2) isn't very graceful が2012年にあがっていますが、ずっと放置されているようです。。。

8
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
11