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

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

问题描述

在一个 php 脚本中,我对不同的 URL 执行了很多不同的 cUrl GET 请求(一百个).

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.

谢谢,

本杰明

推荐答案

这取决于 url 是否在同一台服务器上.如果是,对同一服务器的并发请求将重用连接.请参阅 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.

如果 url 有时在同一台服务器上,您需要对 url 进行排序,因为默认连接缓存限制为 10 或 20 个连接.

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天全站免登陆