对相同域的cURL请求非常慢

I am calling an API with cURL to the same domain (right now its localhost) with the following code

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url ); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch); 
curl_close($ch); 

It is very slow, (up to 7 seconds) unless I add

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,1);

I know its not simply the time it takes for the API to load, because if I request the API url in the browser, its almost instant.

How would you suggest troubleshooting this issue? Or should I not be using cURL at all?