Answer the question
In order to leave comments, you need to log in
How to implement a timer in php that works in conjunction with stream_select?
There is code that fires when an event arrives on one of the listening sockets.
while (true) {
//формируем массив прослушиваемых сокетов:
$read = $connects;
stream_select($read, $write, $except, null);//ожидаем сокеты доступные для чтения (без таймаута)
...обрабатываем $read
}
stream_select($read, $write, $except, 0.05));
$this->base = event_base_new();
$timer = event_timer_new();
event_timer_set($timer, array($this, '_onTimer'), $timer);
event_base_set($timer, $this->base);
event_timer_add($timer);
stream_socket_pair()
, I do fork()
it and in the child process in an endless loop I write data to the pair socket $ parent:while (true) {
fwrite('ping', $parent);
usleep(50000);
}
$read = [$child];
Answer the question
In order to leave comments, you need to log in
There is a puff extension www.php.net/manual/en/class.thread.php but I'm not aware of its quality. One blocking thread reads, the other does the necessary things 20 times per second.
There was a similar task, multithreading is not very friendly with puff, I wrote a layer in C ++
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question