使用PHP Curl库的持久性/保持性HTTP? [英] Persistent/keepalive HTTP with the PHP Curl library?
问题描述
我使用一个简单的PHP库通过HTTP将文档添加到SOLR索引。
目前有3个服务器:
- 运行
-
- 一个保存要编入索引的数据库的数据库
-
$ b在80个文档/秒(100万个文档)中,我注意到在PHP和solr盒子上的网络接口上异常高的中断率(2000 /秒;图形几乎是相同的 - 当PHP盒子上的中断速率上升时,它也在Solr盒子上尖峰),但是在数据库盒子(300 /秒)上更少。我想这只是因为我打开并重新使用到数据库服务器的单个连接,但是每个单个Solr请求目前通过cURL打开一个新的HTTP连接,这要归功于Solr客户端库的写入方式。
所以,我的问题是:
- 可以cURL打开一个keepalive会话吗?
- 重新使用连接需要什么? - 是否像重用cURL句柄资源一样简单?
- 我需要设置任何特殊的cURL选项吗? (例如强制HTTP 1.1?)
- 是否有任何与cURL keepalive连接的问题?此脚本一次运行几个小时;
- 是的,实际上应该默认重用连接,只要重新使用cURL句柄。
- 默认情况下,cURL自己处理持久连接;如果您需要一些特殊的标头,请检查CURLOPT_HTTPHEADER
- 服务器可能会发送保持活动超时(使用默认的Apache安装,它是15秒或100个请求,以先到为准) - 但cURL只会在发生这种情况时打开另一个连接。
- The PHP box running the indexing job
- A database box holding the data being indexed
- The solr box.
- Can cURL be made to open a keepalive session?
- What does it take to reuse a connection? -- is it as simple as reusing the cURL handle resource?
- Do I need to set any special cURL options? (e.g. force HTTP 1.1?)
- Are there any gotchas with cURL keepalive connections? This script runs for hours at a time; will I be able to use a single connection, or will I need to periodically reconnect?
- Yes, actually it should re-use connections by default, as long as you re-use the cURL handle.
- by default, cURL handles persistent connections by itself; should you need some special headers, check CURLOPT_HTTPHEADER
- the server may send a keep-alive timeout (with default Apache install, it is 15 seconds or 100 requests, whichever comes first) - but cURL will just open another connection when that happens.
解决方案cURL PHP文档( curl_setopt )说:
CURLOPT_FORBID_REUSE
-TRUE
在处理完成后明确关闭
的连接,以及
不能合并重用。
所以:
I'm using a simple PHP library to add documents to a SOLR index, via HTTP.
There are 3 servers involved, currently:
At 80 documents/sec (out of 1 million docs), I'm noticing an unusually high interrupt rate on the network interfaces on the PHP and solr boxes (2000/sec; what's more, the graphs are nearly identical -- when the interrupt rate on the PHP box spikes, it also spikes on the Solr box), but much less so on the database box (300/sec). I imagine this is simply because I open and reuse a single connection to the database server, but every single Solr request is currently opening a new HTTP connection via cURL, thanks to the way the Solr client library is written.
So, my question is:
解决方案cURL PHP documentation (curl_setopt) says:
CURLOPT_FORBID_REUSE
-TRUE
to force the connection to explicitly close when it has finished processing, and not be pooled for reuse.So:
这篇关于使用PHP Curl库的持久性/保持性HTTP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!