简体   繁体   中英

Why could Curl be slower than a web browser?

I am using this class to make one GET and another POST request to a website (the first request is to set a cookie). I am testing in a Win XP virtual machine with virtualbox, using wamp from wampserver dot com. The 2 requests takes from 10 to 18 seconds (with curl), but if I make those request directly via the webbrowser in that same virtual machine the website loads in just a few seconds, and it retrieves all the images, css, etc.

What could be causing curl to work so slow? is there a way to fix it?

Curl is probably trying to Reverse DNS the server and, as it cant, it just hangs there a little waiting for the timeout.

If the timeout is given by IPV6 you can try CURL_IPRESOLVE_V4 to bypass it altogether. It really depends on your machine configuration and is more a question to Server Fault.

检查您的Web服务器日志,并尝试查找来自普通Web浏览器的请求和curl请求之间的任何差异

I faced the same issue, using the curl command.

as suggested above - forcing ipv4 only dns lookup fixed it.

curl -4 $url # nice and fast

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

It is probably due to IPv6.

Try add

curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );

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

::1 localhost

to /etc/hosts/ file.

This is the ipv6 notation for 127.0.0.1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM