dongmin3754 2014-09-05 15:49
浏览 68
已采纳

如何在Laravel 4中获得“cron”支持?

Does self-hosted (non-Forge) Laravel have a cron system? Or has this been supplanted by worker queues?

That is, in many PHP frameworks, there's a single cron file to run -- often named cron.php. You're usually instructed to configure this script to run every 15 minutes (or some similar time) via a unix cron job.

1,15,30,45 * * * * /path/to/php /path/to/cron.php

Does Laravel have a similar system? Googling about I've seen some mentions that Forge has a solution for this, and that older version of Laravel might have had a system, but I haven't been able to find a clear answer W/R/T Laravel 4.

  • 写回答

1条回答 默认 最新

  • dscizpq790832708 2014-09-05 16:14
    关注

    You can schedule artisan commands and make your own commands like so:

    php artisan command:make cronCommand
    

    Which will result in a cronCommand.php file in your app/commands directory

    Then you make artisan aware of the command

    Add Artisan::add(new cronCommand); to app/start/artisan.php

    composer dump-autoload
    

    Now you can see your new command via php artisan list

    and schedule it via 1,15,30,45 * * * * artisan cronCommand


    Reference

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?