Laravel 异步请求的最佳实践

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46204673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:38:55  来源:igfitidea点击:

Best Practice for Laravel Asynchronous Requests

phplaravelcurlasynchronouslaravel-5

提问by cyber8200

I have a Laravel application. The application loading perfectly fine, when I only make 3-10 API per page in my controller. Now, I start to see the latency when I start making 200 APIrequests per page in my controller.

我有一个 Laravel 应用程序。当我在控制器中每页只制作 3-10 个 API 时,应用程序加载得非常好。现在,当我开始200 API在控制器中每页发出请求时,我开始看到延迟。

Since Laravel is MVC.

因为 Laravel 是 MVC。

All the code in the controller need to be fully executed and finished, and then it will send all the data/variables to the view. But that is leading to a lot of latency.

控制器中的所有代码都需要完全执行并完成,然后它将所有数据/变量发送到视图。但这会导致很多延迟。

I'm thinking to perform that APIs call asynchronously, but I am not sure which one is the best move,

我正在考虑异步执行 API 调用,但我不确定哪一个是最好的举措,

I did a quick search, I found :

我快速搜索了一下,发现:

Any directions/suggestions on this will mean a lot to me, and others that faced this issue.

对此的任何指示/建议对我和其他面临此问题的人来说都意义重大。

采纳答案by trh88

Explore using Queuesfor this. Offload any calls to the queue, await for response.

为此探索使用队列。将任何呼叫卸载到队列中,等待响应。

I would recommend against 200 requests per page, it seems excessive. Perhaps start with trying to get that down before rearchitecting.

我建议不要每页 200 个请求,这似乎过多。也许从尝试在重新构建之前解决它开始。