|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-02-21 02:41 UTC] matteo at beccati dot com
Description:
------------
Trying to help a friend which wanted to do a curl HEAD request with php (just like the shell curl -I does), I wrote down this code, without much checking:
$ch = curl_init('http://foo/bar.html');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
var_dump(curl_exec($ch));
In fact he tried it and told me it doesn't work, while this does:
$ch = curl_init('http://foo/bar.html');
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
ob_start();
curl_exec($ch);
var_dump(ob_get_clean());
phpinfo() tels me that I'm running:
libcurl/7.10.5 OpenSSL/0.9.7b zlib/1.1.4
I've also seen bug #15279, but it was marked as documentation problem, and didn't explain this weird issue.
Reproduce code:
---------------
$ch = curl_init('http://beccati.com/img/adv.png');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
var_dump(curl_exec($ch));
Expected result:
----------------
string(214) "HTTP/1.1 200 OK
Date: Sat, 21 Feb 2004 07:39:06 GMT
Server: Apache
Last-Modified: Wed, 06 Aug 2003 12:35:16 GMT
ETag: "27c64-204-3f30f604"
Accept-Ranges: bytes
Content-Length: 516
Content-Type: image/png
"
Actual result:
--------------
bool(false)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 21:00:01 2025 UTC |
Works just fine with latest CVS. <?php $ch = curl_init('http://bugs.php.net/'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); var_dump(curl_exec($ch)); ?> Results in: tring(154) "HTTP/1.1 200 OK Date: Sat, 21 Feb 2004 17:19:33 GMT Server: Apache/1.3.28 (Unix) PHP/4.3.4-dev X-Powered-By: PHP/4.3.4-dev Content-Type: text/html "When you run the script, it hangs a while here: curl.c:1021 error = curl_easy_perform(ch->cp); And finally it returns: CURLE_PARTIAL_FILE The error string it gives is: "transfer closed with 6484 bytes remaining to read" Test script: <?php $ch = curl_init('http://bugs.php.net/gifs/logo-bug.gif'); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); var_dump(curl_exec($ch)); ?> (notice: not using CURLOPT_RETURNTRANSFER :)