You are here

function Net_Socket::readLine in Flickr API 5

Read until either the end of the socket or a newline, whichever comes first. Strips the trailing newline from the returned data.

@access public

Return value

All available data up to a newline, without that newline, or until the end of the socket, or a PEAR_Error if not connected.

File

phpFlickr/PEAR/Net/Socket.php, line 437

Class

Net_Socket
Generalized Socket class.

Code

function readLine() {
  if (!is_resource($this->fp)) {
    return $this
      ->raiseError('not connected');
  }
  $line = '';
  $timeout = time() + $this->timeout;
  while (!feof($this->fp) && (!$this->timeout || time() < $timeout)) {
    $line .= @fgets($this->fp, $this->lineLength);
    if (substr($line, -1) == "\n") {
      return rtrim($line, "\r\n");
    }
  }
  return $line;
}