/** * Listens to the connection until it gets data or the timeout is reached. * Thus, it should only be called if data is expected to be received. * @access public * @return mixed either false for timeout or an array with the received data */ public function listen($timeout = 10, $wait = false) { if (!$this->connected()) { return false; } // Wait for a response until timeout is reached $start = time(); $data = ''; do { $read = trim(fread($this->connection, 4096)); $data .= $read; } while (time() <= $start + $timeout && !feof($this->connection) && ($wait || $data == '' || $read != '' || substr(rtrim($data), -1) != '>')); if ($data != '') { $this->log('RECV: ' . $data); return Jabber::xmlize($data); } else { $this->log('Timeout, no response from server.'); return false; } }