0

我正在使用 Laravel 5.3.26 并且无法将调度程序设置为自动运行,尽管我已经准备好 cron 作业。

我创建了一个新命令ligmena:update,下面是代码:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use DB;

class ligmena extends Command {

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'ligmena:update';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Update';

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

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle() {
        //
        $today = strtotime("now");
        $energa_symvolaia = DB::table('symvolaia')->where('eidos_kinisis', '1')->get();
        foreach ($energa_symvolaia as $es) {
            $imerominia_lixis = strtotime(str_replace("/", "-", $es->imerominia_lixis));
            if ($today > $imerominia_lixis)
                DB::table('symvolaia')->where('id', '<', $es->id)->update(['eidos_kinisis' => '4']);
        }
    }

}
?>

下面是代码Kernel.php

<?php

namespace App\Console;

use DB;
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\ligmena::class,
            //
    ];

    /**
     * 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('ligmena:update')->everyMinute();
    }

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

}
?>

我已经像这样设置了 cron 作业:

php /home/site.com/public_html/testdemo/artisan schedule:run >> /dev/null 2>&1

它每分钟运行一次。

如果我手动运行命令,它工作正常。

有什么建议么?

4

1 回答 1

0

我已经使用原始 mysql 解决了这个问题。cron 作业运行良好,代码正常,但没有更改数据库。在我更改为原始 mysql 后,它工作正常

于 2017-09-22T18:07:39.667 回答