Laravle Job 案例

make:job 创建一个新JOb类

protected $msg;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($msg)
{
$this->msg = $msg;
}

/**
* Execute the job.
*
* @return void
*/
public function handle()
{
echo date(‘Y-m-d H:i:s’).”=>”.$this->msg .”\n”;
}
控制器使用案例
for($i = 0; $i < 10; $i ++) {
$job = new TestJob(‘hello ‘. $i);
$this->dispatch($job);
}



Bookmark the permalink.

Comments are closed.