php-4.3.0pre2, fgets and socket_get_status
| From: | Stephen Grier | Date: | Fri, 22 Nov 2002 14:58:56 +0000 |
| Subject: | php-4.3.0pre2, fgets and socket_get_status | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-125616@lists.php.net to get a copy of this message | ||
An application I am developing contains something like the following:
$this->socket = fsockopen($server, $port, $errnum, $errstr, "60");
...
while (!feof($this->socket)) {
$char = fgets($this->socket,1);
if (($char == "\n") || ($char == "\r"))
return $buffer;
}
$buffer .= $char;
}
return $buffer;
This works fine upto php-4.2.x. However, I've recently built and
installed php-4.3.0pre2 and now the above code appears to hang.
Substituting fread in place of fgets solves the problem. I know that
fgets is supposed to be 'binary safe' as of php-4.3 but I'm not sure if
this could be causing the above problem.
Does anyone know of any changes to fgets in php-4.3.0 which might be
causing this? Are there any reasons why I should not use fread instead
of fgets here?
Also, I am looking at using something like:
$status = socket_get_status($this->socket);
if ($status["unread_bytes"] <= 0)
return false;
However, $status["unread_bytes"] always returns 0 until the first call
to fgets($this->socket). Is this right? I'd like to check the status of
the socket before I try to read from it.
Thanks,
Stephen Grier