【问题标题】:Laravel cron job is not working in bluehostLaravel cron 作业在 bluehost 中不起作用
【发布时间】:2018-03-13 20:53:57
【问题描述】:

这是我的 Kernel.php 代码

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

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

这是我的 cronEmail.php 代码

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);
}

当我在 cmd 中运行此命令时,上面的代码工作正常

php artisan schedule:run

我尝试在 bluehost 上运行此命令,但仍然无法正常工作..!!

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

我在 bluehost 服务器上试过上面的命令,但还是不行!!

【问题讨论】:

    标签: php laravel cron


    【解决方案1】:

    请更改您的kernel.php 并检查如下:

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

    更新答案

    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终端

    中运行php artisan inspire 命令

    【讨论】:

    • @Brettlee:是的,但请尝试或运行 php artisanspire 并检查您的 cron 是否正常工作
    • @Brettlee:实际上对我来说使用你的代码并在终端中运行 php artisanspire 命令就可以了
    • 你能告诉我你的命令吗
    猜你喜欢
    • 1970-01-01
    • 2015-02-23
    • 2016-07-21
    • 1970-01-01
    • 1970-01-01
    • 2021-05-02
    • 2018-10-24
    • 1970-01-01
    • 2013-05-10
    相关资源
    最近更新 更多