Using cURL for a HEAD request

I can’t figure out what I’m doing wrong here. The code block is intended to take the URL contained in $url, send a HEAD request and then print the header that comes back.

For this test, I set $url=“”.

$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST,“HEAD”);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

curl_exec only returns true - even though it should return the entire contents since I set RETURNTRANSFER to 1.

Any ideas?

I actually got this solved at another place now, so if anyone else needs to do this, here’s how:

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$r = curl_exec($ch);

I haven’t figured out why CUSTOMREQUEST “HEAD” doesn’t cut it, but HEADER and NOBODY combined appear to do the same.