使用PHP curl_multi异步/并行的HTTP请求 [英] Asynchronous/parallel HTTP requests using PHP curl_multi

查看:447
本文介绍了使用PHP curl_multi异步/并行的HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我看着使卷曲多个请求的可能性。我可能没有完全理解它,所以我只是希望能澄清一些概念。

I recently looked into the possibility of making multiple requests with curl. I may not be understanding it fully, so I am just hoping to clarify some concepts.

这绝对是一个不错的选择,如果你正在获取来自多个来源的内容。这样,你就可以开始从更快的服务器处理结果,同时还在等待慢一些。是否还有意义使用它,如果你是从同一个服务器请求多个页面?将服务器仍然在当时服务于多个页面相同的客户端?

It's definitely a good option if you are fetching content from multiple sources. That way, you can start processing the results from faster servers while still waiting for slower ones. Does it still make sense to use it if you are requesting multiple pages from the same server? Would the server still serve multiple pages at the time to the same client?

推荐答案

您不能做多线程在PHP中,所以你不能够开始处理一个页面,而其他仍然被检索。直到所有页面都检索或超时多卷曲将不会返回控制。因此,这将花费要检索的最慢的页面取为长。您是从串行(卷曲)将并行(multi_curl),这仍将会给你一个很大的推动作用。

You can't do multi-threading in PHP, so you won't be able to start processing one page while the others are still being retrieve. Multi-curl won't return control until all pages are retrieved or timeout. So it will take as long the it takes for the slowest page to be retrieved. You are going from serial (curl) to parallel (multi_curl), which will still give you a big boost.

服务器将服务多个页面到同一客户达到一定配置的限制。请求从服务器5-10页就可以了。

Servers will serve multiple pages to the same client up to a certain configure limit. Requesting 5-10 pages from a server would be fine.

这篇关于使用PHP curl_multi异步/并行的HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆