我正在连接服务器以发出数千个请求。基于我所看到的,看起来RCurl在每次请求时都打开了与服务器的连接。我想知道是否有办法让连接在一段时间内保持打开状态。以下是我在一秒钟内运行两个请求时看到的内容
* About to connect() to gt-tradeview port 80 (#0)
* Trying 192.168.141.136... * connected
* Connected to gt-tradeview (192.168.141.136) port 80 (#0)
> POST /House/TradeView/ajax/varys HTTP/1.1
User-Agent: RCurl
Host: gt-tradeview
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept: application/json
Content-Length: 360
< HTTP/1.1 200 OK
< Content-Length: 1690
< Content-Type: application/json
< Server: Microsoft-HTTPAPI/2.0
< Date: Thu, 09 Jan 2014 14:27:49 GMT
<
* Connection #0 to host gt-tradeview left intact
* About to connect() to gt-tradeview port 80 (#0)
* Trying 192.168.141.136... * connected
* Connected to gt-tradeview (192.168.141.136) port 80 (#0)
> POST /House/TradeView/ajax/varys HTTP/1.1
User-Agent: RCurl
Host: gt-tradeview
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept: application/json
Content-Length: 227
< HTTP/1.1 200 OK
< Content-Length: 195
< Content-Type: application/json
< Server: Microsoft-HTTPAPI/2.0
< Date: Thu, 09 Jan 2014 14:27:49 GMT
<
* Connection #0 to host gt-tradeview left intact
这看起来非常浪费时间,但我不明白为什么它会尝试,因为最后一行是连接完好无损。不过,如果我立刻跑了
Browse[2]> showConnections()
description class mode text isopen can read can write
所以没有任何连接打开?
这是我的curl.opts
mkURL <- function(x) {
names <- names(x)
s <- sprintf("%s=%s",names[1],x[1])
for (i in 2:length(names)) {
s <- sprintf("%s&%s=%s",s,names[i],x[i])
}
URLencode(s)
}
curl.opts = curlOptions(
httpheader = c(
'Content-Type' = "application/x-www-form-urlencoded; charset=UTF-8",
'Accept' = "application/json"
#'Accept-Encoding' = "gzip,deflate,sdch"
),
verbose = TRUE, #change to TRUE for server feedback
header = TRUE,
buffersize = 100000000000,
useragent = "RCurl" ###
)
和电话
curlPerform(url = paste0("http://",serverToHit,"/House/TradeView/ajax/varys"),
#curlPerform(url = "http://192.168.141.148/House/TradeView/ajax/varys",
postfields = mkURL(parameters),
.opts = curl.opts,
writefunction = r$update,
post = 1L,
curl = r$curl())