به صورت پیشفرض برای اجرای Workerها دستور php artisan queue:work رو اجرا میکردم.
اما مشکلی که وجود داشت این بود که با هربار تغییر در کد Jobها نیاز بود که Worker رو restart کنم. این مشکل باعث شد که به دنبال راهحلی باشم تا این مشکل رو حل کنم. 🤔
این شد که با دستور php artisan queue:listen آشنا شدم.
تفاوت اصلی این دو دستور در نحوهی برخوردشون با لاراول هست.
queue:work یکبار فریمورک رو load میکنه و تا زمانی که خودمون دستور به restart ندیم، با همون نسخه به کارش ادامه میده.
این باعث میشه سرعت اجرای Jobها خیلی بالا باشه و منابع سیستم هم کمتر درگیر بشن.
اما queue:listen یه رویکرد متفاوت داره. قبل از اجرای هر Job، فریمورک رو از نو load میکنه.
درسته که این کار باعث کندی اجرای جابها میشه، ولی یه مزیت بزرگ داره و اون اینه که هر تغییری که توی کد ایجاد کنیم، بلافاصله اعمال میشه.
توی محیط توسعه که دائم در حال تغییر کد هستیم، این ویژگی خیلی به کارمون میاد. من الان توی محیط local از queue:listen استفاده میکنم و دیگه نگران restart کردن Workerها نیستم.
ولی روی سرور production همچنان از queue:work استفاده میکنم، چون اونجا performance مهمتره.
#Laravel #PHP #Programming
ترجمه:
I have been working and learning different mechanisms of Laravel queues for some time. 🔍
By default, I used the php artisan queue:work command to run workers.
But the problem was that with every change in the Job code, I needed to restart the Worker. This problem made me look for a solution to solve this problem. 🤔
This is how I got acquainted with the php artisan queue:listen command.
The main difference between these two commands is how they deal with Laravel.
queue:work loads the framework once and continues to work with the same version until we are instructed to restart.
This makes the job execution speed very high and the system resources are less involved.
But queue:listen has a different approach. Before executing each Job, it reloads the framework.
It is true that this slows down the execution of jobs, but it has a big advantage, and that is that any changes we make in the code are applied immediately.
In the development environment where we are constantly changing the code, this feature is very useful. I am now using queue:listen in the local environment and I don’t have to worry about restarting the workers anymore.
But I still use queue:work on the production server, because performance is more important there.
#Laravel #PHP #Programming
By default, I used the php artisan queue:work command to run workers.
But the problem was that with every change in the Job code, I needed to restart the Worker. This problem made me look for a solution to solve this problem. 🤔
This is how I got acquainted with the php artisan queue:listen command.
The main difference between these two commands is how they deal with Laravel.
queue:work loads the framework once and continues to work with the same version until we are instructed to restart.
This makes the job execution speed very high and the system resources are less involved.
But queue:listen has a different approach. Before executing each Job, it reloads the framework.
It is true that this slows down the execution of jobs, but it has a big advantage, and that is that any changes we make in the code are applied immediately.
In the development environment where we are constantly changing the code, this feature is very useful. I am now using queue:listen in the local environment and I don’t have to worry about restarting the workers anymore.
But I still use queue:work on the production server, because performance is more important there.
#Laravel #PHP #Programming