Search code examples
laravellaravel-artisan

Slightly confused about what Artisan::callSilent does


I have a web route in my laravel project, and in that web route currently I'm calling an Artisan command I have defined in app/Console/Commands. I'm doing Artisan::call(command).

So, it's my understanding first of all that when I call it like that, my web request will wait for that to complete before it continues into the next bit of code, is that right? Does it wait for Artisan::call to complete?

I would like a solution that doesn't wait, and I have one potential workaround, but before I use my workaround, I want to make sure Artisan::callSilent() doesn't do what I want it to do. If I use callSilent instead, will that run the artisan command in the backround without blocking the rest of the web request process?


Solution

  • The CallsCommand.php shows the following functions:

       /**
         * Call another console command.
         *
         * @param  \Symfony\Component\Console\Command\Command|string  $command
         * @param  array  $arguments
         * @return int
         */
        public function call($command, array $arguments = [])
        {
            return $this->runCommand($command, $arguments, $this->output);
        }
    
        /**
         * Call another console command without output.
         *
         * @param  \Symfony\Component\Console\Command\Command|string  $command
         * @param  array  $arguments
         * @return int
         */
        public function callSilent($command, array $arguments = [])
        {
            return $this->runCommand($command, $arguments, new NullOutput);
        }
    
    

    So as the comments say, callSilent does the same thing as the call command, but doesn't send any output. There's also a callSilently(), which just calls callSilent, so it's basically an alias.