public function send() { $request = new Gpf_Rpc_Request($this->serverClassName, Gpf_Rpc_Server::RUN_METHOD); $request->addParam(Gpf_Rpc_Server::REQUESTS, $this->requests); if ($this->sessionId != null) { $request->addParam("S", $this->sessionId); } $requestBody = $this->json->encodeResponse($request); $responseText = $this->sendRequest($requestBody); if ($this->debugRequests) { echo "REQUEST: " . $requestBody . "<br/>"; echo "RESPONSE: " . $responseText . "<br/><br/>"; } $responseArray = $this->json->decode($responseText); if (!is_array($responseArray)) { throw new Gpf_Exception("Response decoding failed: not array. Received text: {$responseText}"); } if (count($responseArray) != $this->requests->getCount()) { throw new Gpf_Exception("Response decoding failed: Number of responses is not same as number of requests"); } $exception = false; foreach ($responseArray as $index => $response) { if (is_object($response) && isset($response->e)) { $exception = true; $this->requests->get($index)->setResponseError($response->e); } else { $this->requests->get($index)->setResponse($response); } } if ($exception) { $messages = ''; foreach ($this->requests as $request) { $messages .= $request->getResponseError() . "|"; } } $this->requests = new Gpf_Rpc_Array(); if ($exception) { throw new Gpf_Rpc_ExecutionException($messages); } }