1、创建WsSwoole.php文件(大驼峰命名,自命名)
在项目根目录执行以下命令
#在app/Console/Commands增加一个Swoole.php的文件
php artisan make:command WsSwoole
2、在Kernel.php里增加命令列表(如果定时任务必须加,这个可加可不加,建议加)
Commands\Swoole::Class
<?php
namespace App\Console;
use App\Console\Commands\AccessTokenRevoke;
use App\Console\Commands\UploadPart;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
WsSwoole::Class,//这个可以不加
UploadPart::class
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('accessToken:revoke')->everyFiveMinutes(); //每五分钟调度一次token废弃任务
$schedule->command('pst:uploadpart')->dailyAt('3:00'); //每天3点删除上传产生的碎片
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
3、编辑WsSwoole文件
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class WsSwoole extends Command
{
public $ws;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'swoole {action?}';
/**
* The console command description.
*
*