PHP вызов pcntl_signal_dispatch () каждые несколько секунд

StackOverflow https://stackoverflow.com/questions/9511878

  •  14-11-2019
  •  | 
  •  

Вопрос

У меня есть скрипт PHP, который читает из трубы в режиме блокировки.

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

Я хотел бы иметь возможность иметь PCNTL_Signal_dispatch выполнить каждые несколько секунд, когда мой скрипт ожидает ввода с трубы, не мешая к очерединой трубе.

Любые предложения?

Это было полезно?

Решение

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top