如何在共享主机上运行Cron Job? (流明)

问题描述 投票:1回答:1

我正在尝试在我的流明项目中执行Cron工作。当用户创建预订时,我有BookingMaster Table。我将默认状态设置为B意味着在表中已预订。在预订当天,我正在尝试将状态更新为I到数据库表示正在进行中。当我在本地执行此操作时,cron运行良好,并且状态也在更新。

但是当我将此代码移至共享主机时,它不再起作用。 cron不会更新数据库中的状态。

BookingUpdate.php的位置是-app / Console / Commands / BookingUpdate.php

BookingUpdate.php

<?php

namespace App\Console\Commands;

use Helpers;
use Illuminate\Console\Command;
use App\BookingMaster;

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

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

    public static $process_busy = false;

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

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle(){
        if (self::$process_busy == false) {
            self::$process_busy = true;
            $where['status'] = 'B';
            $update = BookingMaster::updateRecord(6,$where);
            self::$process_busy = false;             
            echo 'Done';
               return true;
        } else {
            if ($debug_mode) {
                error_log("Process busy!", 0);
            }

            return false;
        }


    }
}

karnel.php

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Laravel\Lumen\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        '\App\Console\Commands\BookingUpdate',

    ];

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

Cron Job Command:

/usr/local/bin/php -q /home/rahulsco/public_html/api.pawsticks/artisan schedule:run 1>> /dev/null 2>&1
php laravel cron cpanel lumen
1个回答
0
投票

您的代码无法在Cron中运行,可能会出现几个问题。

  • 也许PHP的正确路径不在/usr/local/bin/php上,尝试仅使用php -q运行Cron
  • 某些系统要求脚本以#!/usr/bin/env php或类似的组合开头。
  • 此部分的Cron命令artisan schedule:run中有一个空格,因此一旦将命令放在引号中并转义了空格,它可能会起作用php -q "/home/rahulsco/public_html/api.pawsticks/artisan\ schedule:run" 1>> /dev/null 2>&1

最后,如果其他任何操作失败,我都会尝试将某些内容记录到文件中并在cron运行之后进行检查,也许目录配置中存在其他错误,导致脚本在写入数据库之前失败,并且cron运行正常...

© www.soinside.com 2019 - 2024. All rights reserved.