Why can Curl be slower than a web browser?

I use this class to make one GET and another POST request to the website (the first request is to set a cookie). I am testing a Win XP virtual machine using a virtual box using wamp from wampserver dot com. 2 requests take from 10 to 18 seconds (with a twist), but if I make these requests directly through a web browser on the same virtual machine, the site loads in just a few seconds and it extracts all the images, css, etc.

What can make curl work so slowly? is there any way to fix it?

+4
source share
5 answers

Check your web server logs and try to find any difference between requests from a regular web browser and requests from curl

+2
source

Curl is probably trying to get the DNS server back and, as it cannot, it just hangs there, waiting for a timeout.

If the timeout is set to IPV6, you can try CURL_IPRESOLVE_V4 to bypass it completely. It really depends on the configuration of your computer and is more related to the problem with the server.

+3
source

I ran into the same problem using the curl command.

as suggested above - force ipv4 recovery only dns.

curl -4 $url # nice and fast

(I already had ::1 localhost in my hosts file, but that didn't help).

+2
source

This is probably due to IPv6.

Try to add

 curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); 
+1
source

I ran into this problem with a local web server. I was able to fix by adding

 ::1 localhost 

to /etc/hosts/ .

This is the ipv6 notation for 127.0.0.1

0
source

All Articles