What is the difference queue:work and queue:listen

前端 未结 4 1325
终归单人心
终归单人心 2020-12-29 20:11

I can\'t understand what\'s the difference between Laravel queue:work and Laravel queue:listen

I can see that:

  • Queue: Listen
4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-29 20:45

    Until Laravel 5.2 you had :listen and :work.

    Work would process the first job in the queue.

    Listen would process all jobs as they came through.

    In Laravel 5.3+ this is no longer the case. Listen still exists, but it is deprecated and slated for removal in 5.5. You should prefer :work now.

    Work now process jobs one after the other, but have a plethora of options you can configure.

    Edit

    The above was true at the time of the posting, but since then things have been changed a bit.

    queue:work should be preferred when you want your queue's to run as a daemon. This would be a long-lived process that would be beneficial where performance was an issue. This will use a cached version of the application and does not re-bootstrap the application every time a job is processed.

    queue:listen should be used when you don't care about performance or you don't want to have to restart the queue after making changes to the code.

    • They'll both pop jobs off the queue 1-by-1 as received.
    • They both share almost the exact same options that can be passed to them.

提交回复
热议问题