Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
439 views
in Technique[技术] by (71.8m points)

scheduled tasks - Corn job isn't working in laravel project on Cpanel

I am trying to setup a Cron job on cpanel which will run after every minute but it's not working.
I think it just won't execute. I want to know what error it is?.

Cron jobs
I don't know if this one works:

/usr/local/bin/php /home/vpstrong/public_html/ai/artisan schedule:run >> /dev/null 2>&1

Commands/DSCCompile.php this is my app/Commands/DSCCompile.php.

<?php

namespace AppConsoleCommands;

use IlluminateConsoleCommand;
use Appwwwusers;
use Apphistory;
use Appdsc_history;
use IlluminateSupportFacadesDB;
use Session;
class DSCCompile extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'cron:dsc';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Send every minute using cron job.';

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

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
       //to run and compile the cron job at the next day 00:01, so the day will be yesterday 

     $yesterday = date('Y-m-d',strtotime("yesterday"));


             $history = DB::table('dsc_history')
    ->select('wwwuserid')
    ->groupBy('wwwuserid')
    ->where('status','=','0')
    ->get();
   
        foreach($history as $value){
            $userid = $value->wwwuserid;
            $amount = DB::table('dsc_history')
            ->where('wwwuserid',$userid)
            ->where('status','=','0')
            ->sum('amount');
        //      $amount     = mysql_fetch_array(mysql_query("select sum(amount) as sum from dsc_history where wwwuserid = '".$userid."' and status = '0' "));    
        // $comm = $amount['sum'];
             $cur_date = date('Y-m-d H:i:s');
             $description="Sharing Bonus for ".$yesterday ;
             $Query =DB::table('wallet_split')
             ->select('*')
             ->where('id','>=','1')
             ->orderBy('id','ASC')
             ->get();
             foreach($Query as $value){
                $percentage = $value->percentage;
                $wallet_name = $value->wallet_name;

                $bonus = $amount * ($percentage/100);
                $desc = $percentage.'% of '.$description;
                $trans_id       = 'DSC'.rand(1,100000000);
                $payid      = $wallet_name;

                $insert = new history([
                'wwwuserid' => $userid,
                'amount' => $bonus,
                'type' => ('bonus'),
                'description'=>$desc,
                'date' =>date('Y-m-d H:i:s'), // current date $cur_date
                'transactionid'=>$trans_id, 
                'gateway_id' =>$payid,
                ]);
                $insert->save();
             }
        }
    }
}

Kernel.php

<?php

namespace AppConsole;


use IlluminateConsoleSchedulingSchedule;
use IlluminateFoundationConsoleKernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        CommandsDSCCompile::class,
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  IlluminateConsoleSchedulingSchedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
            //  code ???????????????
            $schedule->command('cron:dsc')->everyMinute();
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

How to debug or to know why it doesn't work?

question from:https://stackoverflow.com/questions/65952418/corn-job-isnt-working-in-laravel-project-on-cpanel

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...