Laravel的队列和任务调度的区别

如题所述

你好,设置方法如下:
namespace App\Console;

use DB;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel{
/**
* 应用提供的Artisan命令
*
* @var array
*/
protected $commands = [
'App\Console\Commands\Inspire',
];

/**
* 定义应用的命令调度
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->call(function () {
DB::table('recent_users')->delete();
})->daily();
}
}

除了调度闭包调用外,还可以调度Artisan命令和操作系统命令。例如,可以使用command方法来调度一个Artisan命令:
$schedule->command('emails:send --force')->daily();

exec命令可用于发送命令到操作系统:
$schedule->exec('node /home/forge/script.js')->daily();
温馨提示:答案为网友推荐,仅供参考
相似回答