doukuang1950
2017-10-24 12:15 阅读 142
已采纳

Laravel Schedule呼叫助手功能不起作用

I'm trying to run a Helper function (App\Helpers) on a scheduled timer using Laravel (for testing purposes I have it running once every minute). I'm using Laravel 5.3.

This is my schedule function in my Kernel.php...

    protected function schedule(Schedule $schedule)
    {
        $schedule->call(function()
        {
            // Calling this function should write a new file with a random number in it.
            // I know this works perfectly fine outside of the scheduled task because I 
            // call it in other places, and it works)

            FileEdit::UpdateFile();

        })->everyMinute();
    }

The issue is that the FileEdit::UpdateFile() part is NOT ever being called by the laravel at the designated time intervals.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    duanpaotian2348 duanpaotian2348 2017-10-24 12:24

    Are you running a cron job to execute the schedule command every minute?

    https://laravel.com/docs/5.5/scheduling#introduction

    * * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1

    This Cron will call the Laravel command scheduler every minute. When the schedule:run command is executed, Laravel will evaluate your scheduled tasks and runs the tasks that are due.

    点赞 评论 复制链接分享
  • douzhulan1815 douzhulan1815 2017-10-24 12:28

    Your code looks fine, assuming you have cron configured correctly, this may help you debug your issue https://laravel.com/docs/5.5/scheduling#task-hooks

    Still I would double check if your cron is working, and set according to https://laravel.com/docs/5.5/scheduling#introduction

    点赞 评论 复制链接分享

相关推荐