重复使用相同的卷曲句柄。大的性能提高? [英] Reusing the same curl handle. Big performance increase?

查看:105
本文介绍了重复使用相同的卷曲句柄。大的性能提高?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在php脚本中,我正在做不同的cUrl GET请求(一百)到不同的URL。

In a php script I am doing a lot of different cUrl GET requests (a hundred) to different URL.

从curl_init重用相同的curl句柄会改进与cURL请求的响应时间相比,性能是否可以忽略不计?

Is reusing the same curl handle from curl_init will improve the performance or is it negligible compare to the response time of the cURL requests?

我要求的是,因为在当前架构中,保持相同的cUrl

I am asking that because in the current architecture it would be not easy to keep the same cUrl handle.

感谢,

Benjamin

推荐答案

这取决于网址是否在同一台服务器上。如果是,对同一服务器的并发请求将重用连接。请参阅CURLOPT_FORBID_REUSE。

It depends on if the urls are on same servers or not. If they are, concurrent requests to same server will reuse the connection. see CURLOPT_FORBID_REUSE.

如果网址有时位于同一服务器上,则需要对网址进行排序,因为默认连接缓存限制为十或二十个连接。

If the urls are sometimes on same server you need to sort the urls as the default connection cache is limited to ten or twenty connections.

如果他们在不同的服务器上,使用相同的句柄没有速度优势。

If they are on different servers there is no speed advantage on using the same handle.

使用curl_multi_exec可以同时连接到不同的服务器(并行)。即使这样,你需要一些排队,不使用数千个同时连接。

With curl_multi_exec you can connect to different servers at a same time (parallel). Even then you need some queuing to not use thousands of simultaneous connections.

这篇关于重复使用相同的卷曲句柄。大的性能提高?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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