讨论数量:
可以使用wokerman解决,先下载2个包workerman/crontab
,workerman/workerman
www.workerman.net/doc/workerman/co... 文档
composer require workerman/workerman
composer require workerman/crontab
在laravel中使用
执行命令
php artisan make:command crontab
在生成的文件中
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Workerman\Worker;
class Crontab extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'crontab';
/**
* The console command description.
*
* @var string
*/
protected $description = 'crontab';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
*/
public function handle()
{
$worker = new Worker();
$worker->onWorkerStart = [$this, 'onWorkerStart'];
$worker->runAll();
}
public function onWorkerStart()
{
// 每秒执行
new \Workerman\Crontab\Crontab('* * * * * *', function(){
Artisan::call('需要执行的任务');
});
}
}
在命令行工具,项目目录下执行
php artisan crontab
如果想在后台运行,搜索pm2
自己安装试试
可以使用wokerman解决,先下载2个包
workerman/crontab
,workerman/workerman
www.workerman.net/doc/workerman/co... 文档
在laravel中使用
执行命令
在生成的文件中
在命令行工具,项目目录下执行
如果想在后台运行,搜索
pm2
自己安装试试