I wrote a PHP program that intercepts syslog-ng(through syslog-ng.conf), and 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 it is cleanup(2)never called, and I need it to execute before the program exits.
I tried to catch SIGTERM, SIGHUP and SIGPIPE with pcntl_signal(), and this part of the application is working fine (if I use kill -1 in the PHP process, my signal handler gets called and it starts cleanup()), but it seems that I am not receiving these messages from syslog-ng.
I tried setting STDIN to non-blocking, believing that PHP would not call signal handlers because the thread was blocking. This did not work either, my signal handlers will not be called.
How do I know when syslog-ng is about to stop my application, so I can do some cleanup?
Thanks Tom
UPDATE: I tried to catch all signals from 1 to 31, and it still does not receive anything when restarting syslog-ng (or killed with SIGTERM).
source
share