我需要一种异步运行某些任务的方法,因为每个任务之间的执行时间不同,我想使用Laravel Jobs和数据库作为驱动程序以异步方式运行.
我创建了使用命令行测试作业:php artisan make:job TestOne php artisan make:job TestTwo
TestOne.php
<?php
namespace App\Jobs;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class TestOne extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
sleep(5);
foreach (range(1, 10) as $item)
\Log::info("TestOne: item #" . $item);
}
}
Run Code Online (Sandbox Code Playgroud)
TestTwo.php
<?php
namespace …Run Code Online (Sandbox Code Playgroud)