I wrote a PHP program that hooks into syslog-ng
(via syslog-ng.conf
) and it's basically this:
while (!feof(STDIN)) {
$input = fgets(STDIN);
process($input);
}
cleanup();
where process()
and cleanup()
are defined by me.
The problem I am facing is that cleanup(2)
is never called and I need it to be executed before the program exits.
I have tried to catch SIGTERM, SIGHUP and SIGPIPE using pcntl_signal()
and that part of the application seems to work fine (if I use kill -1 on the PHP process, my signal handler gets called and it runs cleanup()
), but it appears that I am not getting those meessages from syslog-ng.
I have tried setting STDIN to non-blocking, thinking that PHP wouldn't call the signal handlers because the stream was blocking. That didn't work either, my signal handlers wouldn't get called.
How do I know when syslog-ng is about to stop my application, so I can do some cleanup?
Thanks, Tom
UPDATE: I've tried to catch all the signals, from 1 to 31 and it still doesn't receive anything when syslog-ng is restarted (or killed with SIGTERM).