Beispiel #1
0
 protected function sendAndReceive($request)
 {
     $f = new SaeFetchurl();
     $cookie = $this->getCookie();
     if ($cookie != '') {
         $f->setHeader("Cookie", $cookie);
     }
     if ($this->keepAlive) {
         $f->setHeader("Connection", "keep-alive");
         $f->setHeader("Keep-Alive", $this->keepAliveTimeout);
     } else {
         $f->setHeader("Connection", "close");
     }
     foreach ($this->header as $name => $value) {
         $f->setHeader($name, $value);
     }
     $f->setMethod("post");
     $f->setPostData($request);
     $f->setConnectTimeout($this->timeout);
     $f->setSendTimeout($this->timeout);
     $f->setReadTimeout($this->timeout);
     $response = $f->fetch($this->url);
     if ($f->errno()) {
         throw new Exception($f->errno() . ": " . $f->errmsg());
     }
     $http_response_header = $f->responseHeaders(false);
     $this->setCookie($http_response_header);
     return $response;
 }
Beispiel #2
0
 public function invoke($functionName, &$arguments = array(), $byRef = false, $resultMode = HproseResultMode::Normal)
 {
     $stream = new HproseStringStream(HproseTags::TagCall);
     $hproseWriter = new HproseWriter($stream);
     $hproseWriter->writeString($functionName, false);
     if (0 < count($arguments) || $byRef) {
         $hproseWriter->reset();
         $hproseWriter->writeList($arguments, false);
     }
     if ($byRef) {
         $hproseWriter->writeBoolean(true);
     }
     $stream->write(HproseTags::TagEnd);
     $request = $stream->toString();
     if ($this->filter) {
         $request = $this->filter->outputFilter($request);
     }
     $stream->close();
     $f = new SaeFetchurl();
     $cookie = $this->getCookie();
     if ($cookie != "") {
         $f->setHeader("Cookie", $cookie);
     }
     if ($this->keepAlive) {
         $f->setHeader("Connection", "keep-alive");
         $f->setHeader("Keep-Alive", $this->keepAliveTimeout);
     } else {
         $f->setHeader("Connection", "close");
     }
     foreach ($this->header as $name => $value) {
         $f->setHeader($name, $value);
     }
     $f->setMethod("post");
     $f->setPostData($request);
     $f->setConnectTimeout($this->timeout);
     $f->setSendTimeout($this->timeout);
     $f->setReadTimeout($this->timeout);
     $response = $f->fetch($this->url);
     if ($f->errno()) {
         throw new HproseException($f->errno() . ": " . $f->errmsg());
     }
     $http_response_header = $f->responseHeaders(false);
     $this->setCookie($http_response_header);
     if ($this->filter) {
         $response = $this->filter->inputFilter($response);
     }
     if ($resultMode == HproseResultMode::RawWithEndTag) {
         return $response;
     }
     if ($resultMode == HproseResultMode::Raw) {
         return substr($response, 0, -1);
     }
     $stream = new HproseStringStream($response);
     $hproseReader = new HproseReader($stream);
     $result = NULL;
     $error = NULL;
     while (($tag = $hproseReader->checkTags(array(HproseTags::TagResult, HproseTags::TagArgument, HproseTags::TagError, HproseTags::TagEnd))) !== HproseTags::TagEnd) {
         switch ($tag) {
             case HproseTags:
                 if ($resultMode == HproseResultMode::Serialized) {
                     $result = $hproseReader->readRaw()->toString();
                 } else {
                     $hproseReader->reset();
                     $result =& $hproseReader->unserialize();
                 }
                 break;
             case HproseTags:
                 $hproseReader->reset();
                 $args =& $hproseReader->readList();
                 for ($i = 0; $i < count($arguments); $i++) {
                     $arguments[$i] =& $args[$i];
                 }
                 break;
             case HproseTags:
                 $hproseReader->reset();
                 $error = new HproseException($hproseReader->readString());
                 break;
         }
     }
     if (!is_null($error)) {
         throw $error;
     }
     return $result;
 }