File tree Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,10 @@ public function read(int $length = 2048): string
7575 throw new ConnectException ('Not initialized socket ' );
7676
7777 $ output = '' ;
78+ $ t = microtime (true );
7879 do {
80+ if (mb_strlen ($ output , '8bit ' ) == 0 && $ this ->timeout > 0 && (microtime (true ) - $ t ) >= $ this ->timeout )
81+ throw new ConnectionTimeoutException ('Read from connection reached timeout after ' . $ this ->timeout . ' seconds. ' );
7982 $ readed = @socket_read ($ this ->socket , $ length - mb_strlen ($ output , '8bit ' ));
8083 if ($ readed === false )
8184 $ this ->throwConnectException ();
Original file line number Diff line number Diff line change @@ -90,11 +90,15 @@ public function write(string $buffer): void
9090 public function read (int $ length = 2048 ): string
9191 {
9292 $ output = '' ;
93+ $ t = microtime (true );
9394 do {
95+ if (mb_strlen ($ output , '8bit ' ) == 0 && $ this ->timeout > 0 && (microtime (true ) - $ t ) >= $ this ->timeout )
96+ throw new ConnectionTimeoutException ('Read from connection reached timeout after ' . $ this ->timeout . ' seconds. ' );
97+
9498 $ readed = stream_get_contents ($ this ->stream , $ length - mb_strlen ($ output , '8bit ' ));
9599
96100 if (stream_get_meta_data ($ this ->stream )['timed_out ' ] ?? false )
97- throw new ConnectionTimeoutException ('Connection timeout reached after ' . $ this ->timeout . ' seconds. ' );
101+ throw new ConnectionTimeoutException ('Stream connection timed out after ' . $ this ->timeout . ' seconds. ' );
98102 if ($ readed === false )
99103 throw new ConnectException ('Read error ' );
100104
You can’t perform that action at this time.
0 commit comments