In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "then implement supervisor to execute asynchronous process in Laravel". In daily operation, I believe that many people have doubts about the problem of implementing asynchronous process in Laravel and then implementing supervisor. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "then realize supervisor to execute asynchronous process in Laravel". Next, please follow the editor to study!
Problem description
When we use the Laravel framework to implement dynamic web pages, if some operations have a large amount of computation, in order not to affect the user experience, we often need to use asynchronous processing. The queues implementation that comes with supervisor and laravel is used here. Let's take a look at the detailed introduction:
Supervisor
Supervisor (http://supervisord.org) is a process management tool written in Python that can be easily used to start, restart, and shut down processes (not just Python processes). In addition to the control of a single process, you can also start and shut down multiple processes at the same time, for example, if an unfortunate server problem causes all applications to be killed, you can use supervisor to start all applications at the same time instead of typing commands one by one.
The method is as follows
1. Install supervisor
Apt-get install supervisor
Restart supervisor:service supervisor restart after installation
two。 Configure the supervisor file
[program:laravel] process_name=% (program_name)% (process_num) 02dcommand=php {{app.root}} / artisan queue:listenautostart=trueautorestart=trueuser=www-datanumprocs=1redirect_stderr=truestdout_logfile= {{app.root}} / storage/logs/queque.log
Supervisor-managed process instructions are configured here to start snooping on the laravel queue. Both the number of processes and the error log address are specified.
3. Queue configuration
Before writing queue code, you need to configure queue, which is located in config/queue.PHP, where you need to configure your queue driver, such as database, Redis, synchronization, etc. Different options have their own configurations. I choose redis to configure here.
For example:
'redis' = > [' driver' = > 'redis',' connection' = > env ('QUEUE_CONNECTION',' default'), 'queue' = >' wordtohtml', 'expire' = > 600,]
4. Write an asynchronous program
The asynchronous program is written in the app/job directory to create its own class, such as Shutdown, and write the constructor and handle function of the class. The handle function is the process of program calculation.
5. Execute asynchronous function
$this- > dispatch (new Shutdown ($vimd))
Using this instruction, you can create an asynchronous program.
At this point, the study on "implementing the asynchronous process in Laravel and then implementing supervisor" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 239
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.