Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Commit 7b97ba6

Browse files
author
Ivan Poddubny
committed
Fixed hanging due to socket error
1 parent ef3de4d commit 7b97ba6

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

phpagi-asmanager.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,20 @@ function read_one_msg($allow_timeout = false)
162162
{
163163
$type = null;
164164

165-
while(false === ($pos = strpos($this->_buffer, "\r\n\r\n"))) {
166-
$this->_buffer .= @fgets($this->socket, 4096);
167-
}
165+
do {
166+
$buf = fgets($this->socket, 4096);
167+
if (false === $buf) {
168+
throw new Exception("Error reading from AMI socket");
169+
}
170+
$this->_buffer .= $buf;
171+
172+
$pos = strpos($this->_buffer, "\r\n\r\n");
173+
if (false !== $pos) {
174+
// there's a full message in the buffer
175+
break;
176+
}
177+
} while (!feof($this->socket));
178+
168179
$msg = substr($this->_buffer, 0, $pos);
169180
$this->_buffer = substr($this->_buffer, $pos+4);
170181

0 commit comments

Comments
 (0)