|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-02-25 14:24 UTC] niko dot sams at gmail dot com
Description: ------------ For some reason fetching the url with lastmodified and etag options doesn't work correctly. The server returns a 200 OK but the HttpRequest doesn't include the body. I can reproduce this on: Ubuntu 12.04 PHP 5.3.10-1ubuntu3.5 Extension Version => 1.7.4 Used Library => Compiled => Linked libcurl => 7.22.0 => 7.22.0 libevent => 1.4 or greater => 2.0.16-stable libz => 1.2.3.4 => 1.2.3.4 libmagic => disabled => disabled Trying curl extension it works as expected. Test script: --------------- <?php $url = 'http://nikosams.blogspot.com/feeds/posts/default?alt=rss'; //get the current last-modified date $r = new HttpRequest($url); $m = $r->send(); $lastModified = $m->getHeader('Last-Modified'); //try to fetch with lastmodified and etag $r = new HttpRequest($url, HTTP_METH_GET, array( 'lastmodified' => strtotime($lastModified), 'etag' => "abcd", //if removed a 304 is returned )); $m = $r->send(); var_dump($r->getHeaders()); echo $r->getRawResponseMessage(); Expected result: ---------------- Response header plus body. Actual result: -------------- Response header only. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 10:00:01 2025 UTC |
Better testcase that doesn't depend on external server: server.php: <?php $sock = socket_create_listen(1234); socket_getsockname($sock, $addr, $port); print "Server Listening on $addr:$port\n"; while($c = socket_accept($sock)) { socket_getpeername($c, $raddr, $rport); print "Received Connection from $raddr:$rport\n"; $buf = ''; do { $l = socket_read($c, 1024); $buf .= $l; } while (substr($buf, -4) != "\r\n\r\n"); echo $buf."\n"; $out = "HTTP/1.1 200 OK Content-Type: text/plain Last-Modified: Mon, 25 Feb 2013 13:35:56 GMT test "; $out = str_replace("\n", "\r\n", $out); echo $out; socket_write($c, $out, strlen($out)); socket_close($c); } socket_close($sock); ?> test.php: <?php $url = 'http://localhost:1234/'; $lastModified = 'Mon, 25 Feb 2013 13:35:56 GMT'; $r = new HttpRequest($url, HTTP_METH_GET, array( 'lastmodified' => strtotime($lastModified), )); $m = $r->send(); echo $r->getRawResponseMessage(); ?>