Today, when using the PHP curl function, it is too slow to find that you need to wait about 5 seconds to get the results. When the same URL is accessed using a browser, the page is immediately available. It was later discovered that, even without PHP, it was slow to use the native command wget under Linux to get the web. It's so weird, it doesn't look like a program, it's a network setup problem.
When executing wget, it can be seen that blocking occurs in the DNS Domain name Resolution section.
$ wget www.myproject.com
--2012-06-18 12:17:30--http://www.myproject.com/
Resolving www.myproject.com ... # stalled here for about 5 seconds
192.168.1.187
Connecting to www.myproject.com|192.168.1.187|:80 ... Connected.
HTTP request sent, awaiting response ... OK
length:unspecified [text/html]
Saving to:index.html?
[<=>] 5,200--.-k/s in 0s
2012-06-18 12:17:35 ($ mb/s)-index.html saved [5200]
I am using the development environment, the domain name resolves to an internal IP. Strangely enough, I use ping www.myproject.com to get an IP address and return an ICMP message. Why is Wget's DNS resolution so slow? Www.2cto.com
Google to StackOverflow above also have a lot of people to mention this problem, there is said to be reverse DNS reverse Domain Name resolution problem, have said to add that domain name in the host file ... will not solve my problem. Baffled by the occasion, suddenly thought last week is IPv6 day, we shipped a mail said the company network has all enable IPV6. Would that be the reason? Follow this clue to find out, sure enough, suddenly enlightened.
$ wget-4 www.myproject.com
The result is returned in an instant. It seems that the operation has not helped us to bind a IPV6 address for this domain name, the entire network upgrade, the default will be the first to resolve the IPV6, in the case of the domain does not IPv6, will wait for IPV6 parsing failure timeout After the normal process to find IPv4 before.
For PHP Curl, just add the following sentence to solve the delay problem:
curl_setopt ($ch, Curlopt_ipresolve, CURL_IPRESOLVE_V4);
Many servers now have IPv6 but no routing and cannot really work, causing unexpected problems. I deeply realize that IPv6 road is long and endless ...
http://www.bkjia.com/PHPjc/478164.html www.bkjia.com true http://www.bkjia.com/PHPjc/478164.html techarticle today, when using the PHP curl function, it is too slow to find that you need to wait about 5 seconds to get the results. While the same URL is accessed using a browser, you can get the page immediately ...