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

我正在尝试在我的 lumen 项目中实施 cron 作业。当用户创建预订时我有 BookingMaster 表 我将默认状态设置为B表示在表中预订。在预订当天,我正在尝试将状态更新为I to database means In-progress。当我在本地执行此操作时,cron 运行完美并且状态也在更新。


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


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


预订更新.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;

        }



    }

}

Cron 作业命令:

/usr/local/bin/php -q /home/rahulsco/public_html/api.pawsticks/artisan schedule:run 1>> /dev/null 2>&1


慕哥9229398
浏览 102回答 3
3回答

人到中年有点甜

使用共享服务器进行测试 - 带有 laravel/lumen API 的 linux。它正在无缝运行。lynx&nbsp;-dump&nbsp;"here&nbsp;your&nbsp;url&nbsp;for&nbsp;api&nbsp;or&nbsp;any&nbsp;external&nbsp;url&nbsp;you&nbsp;want&nbsp;call"注意:将您的网址用双引号括起来

慕桂英4014372

在 app/Console/kernel.php 中,schedule 函数应该是这样的:protected function schedule(Schedule $schedule) {     $schedule->command('BookingUpdate:booking-update')->daily(); }然后您的 BookingUpdate 流程将在每天午夜运行。此外,您可以随时使用以下命令手动执行 cron:php artisan BookingUpdate:booking-update附言。替换BookingUpdate:booking-update为$signature您需要执行的命令类中定义的变量值。

慕姐8265434

您的代码未在 Cron 中运行可能存在几个问题。也许 PHP 的正确路径不在尝试/usr/local/bin/php运行 Cron 上php -q一些系统需要脚本开头#!/usr/bin/env php或一些类似的组合。这部分的 cron 命令中有一个空格artisan schedule:run,因此一旦您将命令放在引号和转义空格中,它可能会起作用&nbsp;php -q "/home/rahulsco/public_html/api.pawsticks/artisan\ schedule:run" 1>> /dev/null 2>&1最后,如果其他任何事情都失败了,我会尝试将某些内容记录到文件中并在 cron 运行后进行检查,也许您的目录配置中存在其他错误导致您的脚本在写入数据库之前失败并且 cron 运行良好......
打开App,查看更多内容
随时随地看视频慕课网APP