I'm connecting to a server to make thousands of requests. Based on what I'm seeing, it looks like RCurl is opening a connection to the server on every request. I'm wondering if there is a way to keep the connection open for a set amount of time. Here is what I see when I run two requests within a second of each other
* 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
It looks like a pretty big waste of time, but I don't see why it tries since the last line is that the connection is left intact. Nevertheless, if I immediately run
Browse[2]> showConnections()
description class mode text isopen can read can write
so there aren't any connections open?
here are my 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" ###
)
and the call
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())