/** * @todo add support for options to be set to the xmlrpc client * @todo on the other hand, the list of allowed xmlrpc server with options might be stored in settings, just like ggwebservices does... * * @param array $body * @return mixed * @throws \UnexpectedValueException */ public function consume($body) { // validate members in $body if (!is_array($body) || empty($body['server']) || empty($body['method']) || isset($body['arguments']) && !is_array($body['arguments'])) { throw new \UnexpectedValueException("Message format unsupported. Received: " . json_encode($body)); } $label = trim(ConsumerCommand::getLabel()); if ($label != '') { $label = " '{$label}'"; } if ($this->logger) { $this->logger->debug("XMLRPC call will be executed from MessageConsumer{$label}: " . $body['method'] . " on server: " . $body['server']); } $encoder = new XE(); $args = array(); foreach ($body['arguments'] as $val) { $args[] = $encoder->encode($val); } $client = new XC($body['server']); $response = $client->send(new XR($body['method'], $args)); if ($response->faultCode() != 0 && $this->logger) { $this->logger->error("XMLRPC call executed from MessageConsumer{$label} failed. Retcode: " . $response->faultCode() . ", Error message: '" . $response->faultString() . "'", array()); } return $response->faultCode() == 0 ? $encoder->decode($response->value()) : null; }
protected function runCommand($consoleCommand, $arguments = array(), $options = array()) { $input = new StringInput($this->buildCommandString($consoleCommand, $arguments, $options)); $label = trim(ConsumerCommand::getLabel()); if ($label != '') { $label = " '{$label}'"; } if ($this->logger) { $this->logger->debug("console command will be executed in-process from MessageConsumer{$label}: " . (string) $input); } $kernel = $this->application->getKernel(); // q: is this helpful / needed ? //$kernel->shutdown(); //$kernel->boot(); $applicationClass = get_class($this->application); $app = new $applicationClass($kernel); $app->setAutoExit(false); $output = new BufferedOutput(); $retCode = $app->run($input, $output); $results = array($retCode, $output->fetch(), ''); if ($retCode != 0 && $this->logger) { $this->logger->error("Console command executed in-process from MessageConsumer{$label} failed. Retcode: {$retCode}, Output: '" . trim($results[1]) . "'", array()); } return $results; }
/** * Runs an sf command as a separate php process - this way we insure the worker is stable (no memleaks or crashes) * * @param string $consoleCommand * @param array $arguments * @param array $options * @return array (positional) retcode, stdout, stderr * @throws ??? * * @todo add support for ttl when executing commands * @todo add a verbose mode: echo to stdout or a log file the results of execution */ protected function runCommand($consoleCommand, $arguments = array(), $options = array()) { $command = $this->consoleCommand; $command .= $this->buildCommandString($consoleCommand, $arguments, $options); $label = trim(ConsumerCommand::getLabel()); if ($label != '') { $label = " '{$label}'"; } if ($this->logger) { $this->logger->debug("Console command will be executed from MessageConsumer{$label}: " . $command); } $process = new Process($command); $retCode = $process->run(); $results = array($retCode, $process->getOutput(), $process->getErrorOutput()); if ($retCode != 0 && $this->logger) { $this->logger->error("Console command executed from MessageConsumer{$label} failed. Retcode: {$retCode}, Error message: '" . trim($results[2]) . "'", array()); } return $results; }