skip to Main Content

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?

2

Answers


  1. Chosen as BEST ANSWER

    Okay, so for the record

    Artisan::call() is blocking, and Artisan::callSilent() ... well, it doesn't even exist on my installed version of laravel, on the server I'm working on, so I have no idea.

    I'm using a workaround like this:

        $command = "php artisan " . $command ." > /dev/null 2>/dev/null &";
        shell_exec($command);
    

  2. The CallsCommand.php shows the following functions:

       /**
         * Call another console command.
         *
         * @param  SymfonyComponentConsoleCommandCommand|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  SymfonyComponentConsoleCommandCommand|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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search