dongzhan1570 2017-07-25 08:40
浏览 49

Laravel 5.4 Scheduler Cron无法在Cloudway服务器上运行

this is my cron job command in cloudway server:

* * * * * php /home/1432345-6789110.cloudwaysapps.com/pedisfdfdsddd/public_html/artisan schedule:run >> /dev/null 2>&1

The cron did run every minute, but it does NOT execute the command. If i type the php artisan command manually: php artisan command:name --> it work.

Below is my kernel.php and customCommand.php kernel.php

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
protected $commands = [
    Commands\CustomCommand::class,
];

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

protected function commands()
{
    require base_path('routes/console.php');
}
}

customCommand.php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use DB;

class CustomCommand extends Command
{
protected $signature = 'command:name';

protected $description = 'Delete all read notifications after 3 days';

public function __construct()
{
    parent::__construct();
}

public function handle()
{
    DB::table('notifications')
        ->whereIn('type', ['App\Notifications\WeeklyReader', 'App\Notifications\WeeklyFile'])
        ->where([
        ['created_at', '<=', \Carbon\Carbon::now()->subDays(3)->toDateTimeString()],
        ['read_at', '!=', 'null'],
        ])
        ->delete();
    $this->info('All notifications are deleted successfully!');
}
}
  • 写回答

1条回答 默认 最新

  • dongpu6141 2017-07-28 14:17
    关注

    In the definition for the method Kernel::schedule, should you not be using the name of the command as defined in the signature variable? For example, instead of custom:command, it should be:

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

    Additionally, I would suggest that you change your cron job to dump the output to a temporary file instead of sending it to /dev/null.

    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计