Run Artisan command

Posted 9 months ago by sghimire

I have been trying to write a large file and calling artisan command from controller, command runs but I am getting time out all the time. Is there anyway to run this artisan command in queue from api(browser) then send it to run in the background like in the terminal, please?

---controller

Artisan::queue('test:ExecuteFile', ['filter' => $request->all(),'--queue' => $fileName]);

---app/Console/kernel.php

 public function queue($command, array $parameters = [], $queue = 'default')
    {
        $this->app['Illuminate\Contracts\Queue\Queue']->push(
            'Illuminate\Foundation\Console\QueuedJob', [$command, $parameters], $queue
        );
    }

---
public function handle()
{
        //getting the filter 
        $filter = $this->argument('filter');

        //getting optional values
        $queueName = $this->option('queue');

    $this->pathToFiles = storage_path() . '/temp/';

    //open the file and add first column's names
        $fp = fopen($this->pathToFiles . $fileName, 'w');
        fputcsv($fp, $columns);

    foreach ($ent as $v) {
        fputcsv($fp, array($v->tax, $v->tap4, $v->grp5, $v->genus, $v->host, $v->country, v->date, $v->id, $v->reg_number));
}
fclose($fp);

}

Please sign in or create an account to participate in this conversation.