I have an API which makes a get request using curl to get response from an external host.
The lookup time is 5 seconds which is about 10-20 times slower than it should be. I also tried file_get_contents(<url>)
and that also takes about 5 seconds.
Then I tried pinging the same source through my VPS (through ssh) and found that DNS lookup time for ping was also 5 secs so I tried changing the dns setting of server and gave it another DNS ip to use (google and one another) and solved the problem for the server. Now the ping from server is instant and doesn't take time to resolve domain name to IP.
However, curl requests still take same time. 5 seconds for an API command is too slow. What can be changed here? What can I do to make this faster?
Here is the curl_info log:
[url] => https://www.hungrybulb.com/pony/relay.php/?object=user&user=4fd582133861b5c74b4dab7ba42934aa1&scene=home-tv+series
[content_type] => text/html; charset=UTF-8
[http_code] => 200
[header_size] => 234
[request_size] => 143
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 5.254223
[namelookup_time] => 5.191469
[connect_time] => 5.192079
[pretransfer_time] => 5.246915
[size_upload] => 0
[size_download] => 1
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 1
[upload_content_length] => 0
[starttransfer_time] => 5.254214
[redirect_time] => 0
[certinfo] => Array
(
)
[request_header] => GET /pony/relay.php/?object=user&user=4fd582133861b5c74b4dab7ba42934aa1&scene=home-tv+series HTTP/1.1
Host: www.hungrybulb.com
Accept: */*
Update 1: The same code works quite fast when I run it on localhost. I assume that is because my local machine's DNS lookup doesn't take time.