/** * Get informations about the shared worker. * * @return array */ public function getInformations() { $this->_client->connect(); $this->_client->writeAll(Backend\Shared::pack(Backend\Shared::TYPE_INFORMATIONS, "")); $this->_client->read(2); // skip type. $length = unpack('Nl', $this->_client->read(4)); $message = $this->_client->read($length['l']); $this->_client->read(1); // skip eom. $this->_client->disconnect(); return unserialize($message); }
/** * Send a request and get a response. * * @param \Hoa\XmlRpc\Message\Request $message Message. * @return \Hoa\XmlRpc\Message\Response * @throws \Hoa\XmlRpc\Exception\Fault */ public function send(Message\Request $message) { $request = $message->__toString(); $this->_client->writeAll($this->getHeader($request)); $response = $this->_client->readAll(); if (false === ($pos = strpos($response, "\r\n\r\n"))) { throw new Exception('Oops, an unknown error occured. Headers seem to be corrupted.', 0); } $response = substr($response, $pos + 4); if (0 !== preg_match('#<methodResponse>(\\s|\\n)*<fault>#i', $response)) { preg_match('#<(i4|int)>(?:\\s|\\n)*(\\d+)(?:\\s|\\n)*</\\1>#i', $response, $faultCodeMatches); preg_match('#<string>(?:\\s|\\n)*(.*)(?:\\s|\\n)*</string>#i', $response, $faultStringMatches); $faultCode = -1; $faultString = 'An ununderstable fault from the server occured.'; if (isset($faultCodeMatches[2])) { $faultCode = $faultCodeMatches[2]; } if (isset($faultStringMatches[1])) { $faultString = $faultStringMatches[1]; } throw new Exception\Fault($faultString, $faultCode, $request); } return new Message\Response($response); }
/** * Stop the shared worker. * * @return bool */ public function stop() { $client = new Socket\Client($this->_socket); $client->connect(); $client->writeAll(static::pack(static::TYPE_STOP, $this->_password)); $client->disconnect(); return true; }