Curl namelookup_time 10 seconds

When executing a basic curl request in PHP, a plain text web page ( http://whatismyip.org/ ) takes more than 10 seconds to respond.

After viewing the information from curl, I am informed that namelookup_time is 10 seconds. I see the same result when running curl from the command line (Terminal).

Why take so long to look for a name , from what I read, it is more than likely something related to the server / my computer on which the PHP file is located.


Here is my code:

$ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, "whatismyip.org"); curl_exec( $ch ); $ci = curl_getinfo($ch); print_r($ci); 

Here is the information:

 [url] => HTTP://whatismyip.org [content_type] => text/plain [http_code] => 200 [header_size] => 45 [request_size] => 53 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 10.549943 [namelookup_time] => 10.100938 [connect_time] => 10.300077 [pretransfer_time] => 10.300079 [size_upload] => 0 [size_download] => 14 [speed_download] => 1 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => 0 [starttransfer_time] => 10.549919 [redirect_time] => 0 [certinfo] => Array ( ) 
+4
source share
3 answers

I cannot repeat this using the code above - namelookup_time on my (Windows) machine returns as 0 , with total_time being ~ 0.5 . namelookup_time is the time that the OS took to resolve the DNS name for whatismyip.org , so you need to check the DNS configuration of your server.

Assuming your configured primary DNS server does not exist / does not work, and the timeout is 10 seconds. This means that the OS will wait 10 seconds, trying to contact the primary DNS, and when this time fails on the secondary, which works.

What are your configured DNS servers? Try using 8.8.8.8 (Google) as your primary DNS, if necessary.

As a side note, it is best to specify the full URL for cURL, so use http://whatismyip.org/ instead of just whatismyip.org - although this does not seem to be the cause of this particular problem.

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

Solved the problem for me. IPV6 received an unclear error.

+6
source

Probably one of your DNS servers is not responding in a timely manner. Try this command for all IP addresses listed in /etc/resolv.conf:

 dig @IP.TO.DNS.SERVER google.com 

If I am right, one of your DNS servers is not responding.

+1
source

Source: https://habr.com/ru/post/1389063/


All Articles