I am trying to write a native PHP cli application which reads data (log data) from stdin and does some handling after.
I got a first working version with a simple while-Loop:
while ($line = fgets(STDIN)) {
// Do my stuff here
}
When installing signal handling via
function signal_handler(int $signo, mixed $siginfo) {
// ...
}
pcntl_async_signals(TRUE);
pcntl_signal(SIGHUP, 'signal_handler');
this works partly: The signals are only processed after each fgets().
I tried to use stream_select() with NULL as timeout and some other stuff, but this lead to a massive system load 🙂
Is there any best practise to use stream_select() and fgets() on stdin to read data until it’s “ready” and wait/pause indefinitely else but let signals being processed?