0
点赞
收藏
分享

微信扫一扫

laravel中使用定时器

code_balance 2022-06-06 阅读 59

crontab -e 添加每分钟执行 php artisan schedule:run 命令

* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1

在项目路的根目录下输入下面的命令

php artisan make:command Test

会在app/Console/Commands目录下生成一个php文件

<?php

namespace App\Console\Commands;

use App\Post;
use Illuminate\Console\Command;

class Test extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'test';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Command test';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{

//向日志文件中写入一条数据
\Log::info("ffffffffffffffffffff".date("Y-m-d H:i:s"));
}
}

修改app/Console下的Kernel.php,在Kernel.php的schedule方法中添加如下代码:

$schedule->command('test')//Test.php中的name
->everyMinute();


举报

相关推荐

0 条评论