php - Run console command background after login Symfony2 -
i want run custom symfony2 console command background after login. make listener , try use process run command @ background function not work well. here code
class loginlistener { protected $doctrine; private $recommendjobservice; public function __construct(doctrine $doctrine) { $this->doctrine = $doctrine; } public function onlogin(interactiveloginevent $event) { $user = $event->getauthenticationtoken()->getuser(); if($user) { $process = new process('ls -lsa'); $process->start(function ($type, $buffer) { $command = $this->recommendjobservice; $input = new argvinput(); $output = new consoleoutput(); $command->execute($input, $output); echo "1"; }); } } public function setrecommendjobservice($recommendjobservice) { $this->recommendjobservice = $recommendjobservice; } }
is there wrong code? thx helping.
any variables need access inside anonymous function have use use
statement. further $this conflict due scope.
$that = $this; $process->start(function ($type, $buffer) use ($that) { $command = $that->recommendjobservice; $input = new argvinput(); $output = new consoleoutput(); $command->execute($input, $output); echo "1"; });
also can take anonymous function , test outside of start() method this.
$closure = function ($type, $buffer) use ($that) { $command = $that->recommendjobservice; $input = new argvinput(); $output = new consoleoutput(); $command->execute($input, $output); echo "1"; }; $closure();
then can put debugging in there , see if runs. i'm not sure if echo way deal console. recommend monolog or $output->writeln($text);
command.
Comments
Post a Comment