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
Best Practice for Laravel Asynchronous Requests
提问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 API
requests 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 :
我快速搜索了一下,发现:
- PHP cURL Async: http://php.net/manual/en/function.curl-multi-init.php
- Laravel Async: https://laravel.com/docs/5.1/queues
- PHP Promise: https://github.com/reactphp/promise
- PHP cURL 异步:http: //php.net/manual/en/function.curl-multi-init.php
- Laravel 异步:https://laravel.com/docs/5.1/queues
- PHP 承诺:https: //github.com/reactphp/promise
Any directions/suggestions on this will mean a lot to me, and others that faced this issue.
对此的任何指示/建议对我和其他面临此问题的人来说都意义重大。