Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am moving all my server's log rotation tasks for logrotate. The server has several PHP-FPM pools, each of them configured with a separated error_log directive.

The logrotate recipe for the logs is fairly simple:

        rotate 7
                # Need for signaling the php-fpm process?

Should I send some signal to php-fpm pools to catch the new handles for the error_log files (in postrotate script)? If yes, which signal?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

In addition to the normal signals, PHP-FPM recognizes two 'user-defined' signals: SIGUSR1 and SIGUSR2.

  • SIGUSR1 - will cycle the log files
  • SIGUSR2 - graceful reload of all workers + reload of fpm conf/binary

For log file rotation, SIGUSR1 would be well suited. With specific reference to your scenario, a sample logrotate config is detailed on this page. The signal is passed as follows:

kill -USR1 `cat /path/to/`

PHP-FPM signals are defined at:

share|improve this answer
Thanks for your answer! Can you confirm that SIGUSR1 is needed also to rotate the pools' logs? In the referred page, they discuss only about the php-fpm's main log that is apparently "always open" by the process. However, calling SIGUSR1 does not hurt... ;) –  Ville Mattila Nov 2 '12 at 9:03
With most setups, logrotate will move the old file and create a new one. If a process holds a file handle to the original file, it will continue to write to that file even though it has been moved (i.e. it will not use the new file). There are several solutions to this: a) use copytruncate - which will copy the file and truncate the original, so the file being written to is the truncated one b) send the logging process a signal to reload its log files c) pipe logs through an intermediate process which will deal with rotation. –  cyberx86 Nov 4 '12 at 4:15
There are a few additional possibilities that complicate things - PHP-FPM can pass errors back through to the web server (which will handle logging) or it can write the logs directly. In essence, if the logging process keeps its file handle to the log (which would be probable in most cases) then you should signal to it that it needs to reload the logs. –  cyberx86 Nov 4 '12 at 4:26
I see, thanks. I have configured the PHP-FPM pools to write the error_logs themselves. I will need to do some more research to confirm that SIGUSR1 really cycles pool logs too. If it does not, copytruncate might be the best way to go then. Maybe somewhere from PHP-FPM source I could find whether error_log handles are opened on request (no need for signaling) or if the handles are kept open always (signaling or copytruncate required). Let's see... –  Ville Mattila Nov 4 '12 at 15:07

Yes, you need to send this signal, but instead of doing it manually, it is better to add the call of follow script: ... postrotate /usr/lib/php5/php5-fpm-reopenlogs endscript ...

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.