/** * @param bool $waitResponse * @return mixed * @throws FaultException */ private function flush($waitResponse = false) { $r = array($this->socket); while ($waitResponse || @stream_select($r, $w, $e, 0) > 0) { list($handle, $xml) = $this->readMessage(); list($type, $value) = Request::decode($xml); switch ($type) { case 'fault': throw FaultException::create($value['faultString'], $value['faultCode']); case 'response': if ($handle == $this->requestHandle) { return $value; } break; case 'call': $this->callbacksBuffer[] = $value; } } }