From 0279dd90e637326e8b6030091ece7c959e13dac8 Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Sat, 7 Feb 2026 14:13:56 -0700 Subject: [PATCH] Add timeout parameter to read_event method Updated read_event method to accept a timeout parameter for stream_select. --- resources/classes/event_socket.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/resources/classes/event_socket.php b/resources/classes/event_socket.php index afebad52f9..267a7c592f 100644 --- a/resources/classes/event_socket.php +++ b/resources/classes/event_socket.php @@ -126,11 +126,13 @@ class event_socket { /** * Read the event body from the socket - * + * + * @param int|null $timeout the timeout in microseconds for stream_select, Default 10000 + * * @return mixed Content body or false if not connected or empty message * @depends buffer::class */ - public function read_event() { + public function read_event($timeout = 10000) { if (!$this->connected()) { return false; } @@ -152,8 +154,16 @@ class event_socket { break; } - $buffer = fgets($this->fp, 1024); - $b->append($buffer); + // Check if we have data available + $read = [$this->fp]; + $write = []; + $except = []; + if (stream_select($read, $write, $except, 0, $timeout) > 0) { + $buffer = fgets($this->fp, 1024); + if ($buffer !== false) { + $b->append($buffer); + } + } } if (array_key_exists('Content-Length', $content)) {