Does anyone know of any significant changes to the fgets() function in php-4.3.0pre2 which might affect reading from a socket a single byte at a time in the way I describe below? I've had to change to using fread() instead, which is fine, but I'd like to know why I've had to do this, and whether this behaviour is a bug or intentional change in php-4.3.0pre2.
Thanks, Stephen Stephen Grier wrote: > > 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php