Question

I have a PHP script that reads from a pipe in blocking mode.

while($input = trim(fgets($pipe))) { do some stuff }

I would like to be able to have pcntl_signal_dispatch execute every few seconds while my script is awaiting input from the pipe, without disturbing the queued pipe read.

Any suggestions?

Was it helpful?

Solution

As far as I know, you can't respond to signals when the script is blocking. You'd have to either do non-blocking reads from your pipe or do the reads within one process and dispatch the signals in the other (read in the child and pass back to the parent via pipe, have parent respond to signals). If you were reading in the child and passing back to the parent via pipe, then you may not in fact need the signals.

Read this, it will make more sense (contains step-by-step code):

http://www.tuxradar.com/practicalphp/16/1/9

... and the overall parent page:

http://www.tuxradar.com/practicalphp/16/0/0

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top