• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

laravel cron工作不起作用

用户头像
it1352
帮助1

问题说明

我的laravel cron作业无法自动运行.我对其进行了测试,并且似乎可以正常工作,当我使用php artisan checkCommissions:check_commissions时,它可以完美地运行我的任务.所以我认为问题出在我用cpanel编写的命令中,所以有什么帮助吗?

my laravel cron job it does not work automatically. I test it and it seems to work, when I php artisan checkCommissions:check_commissions it runs my task perfectly. so I think the problem is with the command I wrote in cpanel so any help ?

app \ Console \ Commands \ CheckCommissions.php:

app\Console\Commands\CheckCommissions.php:

namespace App\Console\Commands;

use Illuminate\Console\Command;

use App\Models\User;
use App\Models\Setting;
use App\Models\Commission;

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

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Check users counters and give them commissions';

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

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $maxout = Setting::where('name', 'maxout')->first();
        if (!is_null($maxout)) {
            $maxout = $maxout->value;
        }

        if (is_null($maxout) || !is_numeric($maxout) || $maxout < 0) {
            $maxout = 0;
        }

        $commission = Setting::where('name', 'commission')->first();
        if (!is_null($commission)) {
            $commission = $commission->value;
        }

        if (is_null($commission) || !is_numeric($commission) || $commission < 0) {
            $commission = 0;
        }

        $users = User::all();

        foreach ($users as $user) {
            if ($user->counter_right >= $maxout && $user->counter_left >= $maxout) {
                $num = $maxout;
                $update_counters = User::where('id', $user->id)->update(['counter_left' => 0, 'counter_right' => 0]);
            } else {
                if ($user->counter_right >= $user->counter_left) {
                    $num = $user->counter_left;
                } else {
                    $num = $user->counter_right;
                }

                $update_counters = User::where('id', $user->id)->update(['counter_left' => $user->counter_left - $num, 'counter_right' => $user->counter_right - $num]);
            }

            if($num > 0) {
                $money = $num * ($commission / 2);

                $update_user = User::where('id', $user->id)->update(['money' => $user->money   $money]);

                Commission::insert(['user_id' => $user->id, 'money' => $money]);
            }
        }
    }
}

app \ Console \ kernel.php:

app\Console\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\checkCommissions',
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // $schedule->command('inspire')
        //          ->hourly();

        $schedule->command('checkCommissions:check_commissions')
                 ->everyMinute(); //
    }

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

以及Cpanel中的命令:

and the command in Cpanel:

分钟小时月份月份工作日命令操作

Minute Hour Day Month Weekday Command Actions

0 0 * * * /usr/local/bin/php /home/gridtumg/public_html/tree/local/artisan checkCommissions:check_commissions >> /dev/null 2>&1

正确答案

#1

首先,欢迎使用StackOverflow.是的,您的命令是错误的...您想在应用程序控制台内核中运行计划的命令,而不是计划命令执行.请阅读有关任务计划的Laravel官方文档(也许还有查看全文

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcffhaj
系列文章
更多 icon
同类精品
更多 icon
继续加载