简体   繁体   中英

Run Laravel cron job in a background - Laravel 5.8

I have a cron job with Laravel:

    public function handle(){
    $reimport = $this->argument('reimport');

    $lib = new CustomLibrary();

    $lib->importAll();

}

I am calling this in my controller:

Artisan::call('my_command');

or in SSH :

php artisan my_command

Te problem is that in both places the job is not in a background, because it takes more than minute to finish.

Is there way to make that job to run in a background in the controller and in SSH (optional) ?

To start the Laravel Scheduler itself, we only need to add one Cron job which executes every minute. Go to your terminal, ssh into your server, cd into your project and run this command.

crontab -e

This will open the server Crontab file, paste the code below into the file, save and then exit.

* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1

Do not forget to replace /path/to/artisan with the full path to the Artisan command of your Laravel Application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM