In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "laravel can solve any problem with queue", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "laravel queue can solve what problem" article.
In laravel, using queues can solve the problems of large concurrency and multi-language communication interface. Time-consuming tasks or tasks that cannot be parallelized at the same time can be encapsulated and transmitted to the message queue, and messages can be continuously extracted from the message queue and processed by the handler. in this way, the message queue can be used so that there is no congestion in the case of large concurrency.
This article operating environment: Windows10 system, Laravel6 version, Dell G3 computer.
Why does laravel use queues
Message queuing is an essential module for large-scale Web projects, through which the problems of large concurrency and multi-language communication interface can be solved.
For the problem of large concurrency, time-consuming tasks or tasks that cannot be parallelized at the same time can be encapsulated and transmitted to the message queue, and messages are continuously extracted from the message queue and processed by the processor. In this way, the buffer of the message queue can no longer block in the case of large concurrency, and if the performance is not enough, multiple processing tasks can be added to obtain messages from the message queue for processing.
For example, in the operation of the database, when there are too many read and write operations to the database, there will be table locking and other problems. The reading problem can be solved through caching and other solutions, and the writing problem needs to be solved by message queue.
Moreover, in the development of large-scale Web projects, it is impossible to achieve through one language in many cases, and we need to take the advantages of different languages, such as PHP. Although it can do everything in Web development in a theoretical sense, some problems will be very inefficient, such as real-time socket connections and distributed transaction processing.
The message queue of Laravel is used to handle asynchronous tasks, Redis is used as the queue database, and the Supervisor monitoring script interrupts abnormally and restarts automatically, which is the standard process for Laravel to deal with queue tasks, but in practice, there may be a variety of problems. In order to ensure the reliability of the system, we should pay attention to several problems.
I. setting the number of failed retries
Be sure to set the number of failed retries of the task to avoid unlimited retries. If you exceed the number of retries, Laravel will be written to the failed task table by default, or you can write the logic for subsequent processing of failed tasks.
Php artisan queue:work redis-tries=3
You need to first execute the following command to create the datasheet:
Php artisan queue:failed-table
Php artisan migrate
Second, the handling of program exceptions
Sometimes an exception occurs during the execution of the program, such as relying on other APIs, requesting HTTP API timeout, and so on. If the exception is not caught, the current queue will be interrupted and cannot continue to run. For example, if you push content to 10000 users, you need to rely on the API push. If the intermediate request fails, the subsequent push will be affected.
The exception here refers to the exception that occurs during the execution of the program, not that the resident process hangs, the program exception does not necessarily cause the resident process to be interrupted, and the process interruption is monitored and restarted by Supervisor.
For example, capture exception code snippets:
Try {undefined$r = $client- > request ('POST',', ['query' = > [' client_name' = > 'filemail','client_version' = >' 1.0 'result); if ($result [result'] = = 0) {undefinedinfo ("sendMail fail:". Json_encode ($result); $this- > pushLog ($task ['id'], $task [' mail_id'], implode (',', $userIds), json_encode ($result), 0);} else {undefinedLog::warning ("sendMail fail:". Json_encode ($result); $this- > pushLog ($task ['id'], $task [' mail_id'], implode (',', $userIds), json_encode ($result), $result ['result']);} catch (RequestException $e) {undefinedLog::warning (' RequestException'. E-> getMessage ();} catch (Exception $e) {undefinedLog::emergency ('Exception'. $e-> getMessage ();} the above is about "what problems can laravel solve with queues". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about it, please pay attention to the industry information channel.
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: 0
*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.