serviceContainer = $serviceContainer; } /** * $msg will be an instance of `PhpAmqpLib\Message\AMQPMessage` * with the $msg->body being the data sent over RabbitMQ. * * @param AMQPMessage $msg */ public function execute(AMQPMessage $msg) { $msgBody = unserialize($msg->body); if (isset($msgBody['name']) && isset($msgBody['args'])) { // command name and args $name = $msgBody['name']; $args = $msgBody['args']; $input = array(); foreach ($args as $arg) { $arg = str_replace('\\', '\\\\', $arg); $pos = strpos($arg, ':'); $pos2 = strpos($arg, '--'); if ($pos2 === false) { // command argument, no option $input[] = substr($arg, $pos + 1); } else { // reemplazo el primer : por = para las options $input[] = preg_replace('/:/', '=', $arg, 1); } } if(in_array("--executeName",$input)) { $execute = $name; } else { $consolePath = $this->serviceContainer->get('kernel')->getRootDir() . '/../bin/console'; $command = $name . ' ' . implode(' ', $input); $execute = "{$consolePath} {$command}"; } try { $process = new Process($execute); $process->setTimeout(10 * 60); $process->run(); $content = $process->getOutput(); echo $content; } catch (ProcessFailedException $e) { echo 'KILL COMMAND: ', $e->getMessage(), "\n"; } catch (\Exception $e) { echo 'KILL COMMAND: ', $e->getMessage(), "\n"; } return true; } return false; } }