简体   繁体   中英

Laravel cron job is not working in bluehost

Here is my code of Kernel.php

protected $commands = [
    'App\Console\Commands\cronEmail'
];

protected function schedule(Schedule $schedule)
{
     $schedule->command('inspire')->everyMinute();
}

Here is my cronEmail.php code

protected $signature = 'inspire';
 public function handle()
{
    $name="asdfasdfasfd";
    $email="asdfasdfasfd";
    $phone="asdfasdfasfd";
    $pass="asdfasdfasfd";
    $type="asdfasdfasfd";
    $discount=32542345;
    $data=array("customer_name"=>$name,"customer_email"=>$email,"customer_phone"=>$phone,"customer_password"=>$pass,"customer_type"=>$type,"customer_discount"=>$discount);
    DB::table('customer_det')->insert($data);
}

Above of my code is working fine when i run this command in cmd

php artisan schedule:run

I tried running this command on bluehost but it's still not working ..!!

/usr/bin/php /home2/pakhakee/public_html/esabzi/artisan schedule:run 1>> /dev/null 2>&1

I tried above command on bluehost server but it's still not working!!

Please change your kernel.php and check like:

protected $commands = [
    \App\Console\Commands\cronEmail::class

];

Updated Answer

cronEmail.php

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use DB;
use Config;
use Mail;

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


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

        /**
         * Execute the console command.
         *
         * @return mixed
         */
        public function handle()
        {
                $name="asdfasdfasfd";
            $email="asdfasdfasfd";
            $phone="asdfasdfasfd";
            $pass="asdfasdfasfd";
            $type="asdfasdfasfd";
            $discount=32542345;
            $data=array("customer_name"=>$name,"customer_email"=>$email,"customer_phone"=>$phone,"customer_password"=>$pass,"customer_type"=>$type,"customer_discount"=>$discount);
            DB::table('customer_det')->insert($data);
        }
}

AND run php artisan inspire command in Terminal

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM