Question: I have simple code that does a head request for a URL and then prints the response headers. I've noticed that on some sites, this can take a long time to complete.

For example, requesting `http://www.arstechnica.com` takes about two minutes. I've tried the same request using another web site that does the same basic task, and it comes back immediately. So there must be something I have set incorrectly that's causing this delay.

Here's the code I have:

```
$ch = curl_init();
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt ($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);

// Only calling the head
curl_setopt($ch, CURLOPT_HEADER, true); // header will be at output
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); // HTTP request is 'HEAD'

$content = curl_exec ($ch);
curl_close ($ch);

```

Here's a link to the web site that does the same function: <http://www.seoconsultants.com/tools/headers.asp>

The code above, at least on my server, takes two minutes to retrieve www.arstechnica.com, but the service at the link above returns it right away.

What am I missing?

Answer: 
Try simplifying it a little bit:

```
print htmlentities(file_get_contents("http://www.arstechnica.com"));

```

The above outputs instantly on my webserver. If it doesn't on yours, there's a good chance your web host has some kind of setting in place to throttle these kind of requests.

**EDIT**:

Since the above happens instantly for you, try setting [this curl setting](http://www.php.net/manual/en/function.curl-setopt.php) on your original code:

```
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);

```

Using the tool you posted, I noticed that `http://www.arstechnica.com` has a 301 header sent for any request sent to it. It is possible that cURL is getting this and not following the new Location specified to it, thus causing your script to hang.

**SECOND EDIT**:

Curiously enough, trying the same code you have above was making my webserver hang too. I replaced this code:

```
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); // HTTP request is 'HEAD'

```

With this:

```
curl_setopt($ch, CURLOPT_NOBODY, true);

```

Which is the way [the manual](http://www.php.net/manual/en/function.curl-setopt.php) recommends you do a HEAD request. It made it work instantly.
This:

```
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

```

I wasn't trying to get headers.  

I was just trying to make the page load of some data not take 2 minutes similar to described above.  

That magical little options has dropped it down to 2 seconds.