Example #1
0
 /**
  * Invokes the provided request on the XML-RPC server
  * @param Request $request XML-RPC request
  * @return Response The response from the server
  */
 public function invoke(Request $request)
 {
     $requestXml = $request->getXmlString();
     $connection = @fsockopen($this->host, $this->port, $errno, $errstr);
     if (!$connection) {
         throw new ConnectionException($this->host, $this->port, $errstr, $errno);
     }
     $contentLength = strlen($requestXml);
     $headers = array("POST {$this->path} HTTP/1.0", "User-Agent: Zibo", "Host: {$this->host}", "Connection: close", "Content-Type: text/xml", "Content-Length: {$contentLength}");
     fwrite($connection, implode("\r\n", $headers));
     fwrite($connection, "\r\n\r\n");
     fwrite($connection, $requestXml);
     $response = '';
     while (!feof($connection)) {
         $response .= fgets($connection, 1024);
     }
     fclose($connection);
     #strip headers off of response
     $responseXml = substr($response, strpos($response, "\r\n\r\n") + 4);
     $response = Response::fromXMLString($responseXml);
     return $response;
 }