Take the 2-minute tour ×

I am having trouble with some Http Client connections returning NoHttpResponseException about 1 in 3 times.

My hypothesis is that the firewall is closing idle connections (not unusual). I would like to use curl to mimic this.

I have been trying something like this but very likely the connection never goes idle

curl --keepalive-time 60 --limit-rate 128B $URL $URL $URL $URL $URL $URL $URL $URL $URL $URL $URL $URL $URL $URL

What I would like is something akin to

curl $URL
sleep 10
curl $URL    
sleep 20
curl $URL 
sleep 30
curl $URL 

Where each time (using some magic!) Curl reuses the same connection.

Is there any way to do this using curl (or wget) and not have to write a program to do it

share|improve this question
add comment

3 Answers

up vote 9 down vote accepted

There is no such thing you couldn't do with netcat.

REQ="GET / HTTP/1.1\nHost: localhost\nAccept: *\n\n"
(echo -ne $REQ; sleep 1; echo -ne $REQ; sleep 2; echo -ne $REQ) | netcat localhost 80

Change the path to something different than / if you need it...

share|improve this answer
Other useful things to put in the subshell are while sleep 1; echo -ne $REQ; done (1-second spaced requests), head -1 > /dev/null (wait for enter). Also, the request can be set Connection: Keep-Alive if that's what you want to mimic. –  yingted Jan 28 '13 at 23:02
that is of course a very poor HTTP client, but if that's the sufficient level for the user then it is a nice approach... I would only add that echo doesn't have any flags in POSIX so -ne requires a special shell. Use 'printf' instead to be shell independent! –  Daniel Stenberg Jan 29 '13 at 15:10
add comment

No, there's no way for neither curl nor wget to do this. When the tool exits, it will close all connections.

I'd say that the best option for you is to use a scripting language and perhaps a libcurl binding that allows you do to all the curl magic in a more programmatic way. That way you can do a request, sleep 10 seconds and then do another request and it will then re-use the same connection - as far as possible.

There are libcurl bindings available for pretty much any programming language of your choice, and even when not using libcurl you can probably achieve this functionality although perhaps not with the same ease.

share|improve this answer
add comment

I'm not sure but If you allow to use programming option then multi-curl in PHP can give you the expected result and you will not need to use sleep as well. Multi-curl will run all request in parallel process.


If you want to use it, I can send you the code.

share|improve this answer
add comment

Your Answer


