laravel中使用定时任务和队列

1.使用命令生成定时任务类:

php artisan make:command RegCustomer

这样会在app/Console/Commands 下生成一个php 文件在这里插入图片描述
在handle中写上你的业务代码,Kernel.php 里面调用

<?php

namespace App\Console;

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 = [
        //
        \App\Console\Commands\Stat_Test::class
    ];
    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
		$schedule->command('Stat:test')->everyMinute();
    }

    /**
     * Register the Closure based commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        require base_path('routes/console.php');
    }
}

使用命令生成队列类

php artisan make:job RegCustomer  

在handle中写上你的业务代码

外部调用

 public function queque(){
        \App\Jobs\RegCustomer::dispatch();
        echo '王召波队列演示';die;
    }  

* * * * * php /www/blog-pay/artisan schedule:run
* * * * * php /home/pikiadmin/ec-commerce/blog-pay/artisan schedule:run
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值