Bug #54917 [Opn->Bgs]: Incorrect behavior of the sockets functions when using HTTP-connections
| From: | bjori@php.net | Date: | Sun, 29 May 2011 15:34:10 +0000 |
| Subject: | Bug #54917 [Opn->Bgs]: Incorrect behavior of the sockets functions when using HTTP-connections | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-161031@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=54917&edit=1
ID: 54917
Updated by: bjori@php.net
Reported by: euxomen at mail dot ru
Summary: Incorrect behavior of the sockets functions when
using HTTP-connections
-Status: Open
+Status: Bogus
Type: Bug
Package: Sockets related
Operating System: Windows 7, Ubuntu 10.10
PHP Version: 5.3SVN-2011-05-24 (snap)
Block user comment: N
Private report: N
New Comment:
Your script is wrong.
feof() will not return true until the connection has timedout, which
means your
second request never gets written.
If you change the while loop to read the content-length data after the
headers it
will work fine.
Previous Comments:
------------------------------------------------------------------------
[2011-05-24 15:46:14] euxomen at mail dot ru
Description:
------------
When I try to make HTTP keep-alive connection, script behaves
ununderstood.
When I am making two request per one connection, using header
"Connection:keep-
alive", script processes only one. Second request, although it was
written into
socket, it returns an empty result, due to the fact that the pointer is
EOF.
Test script:
---------------
<?php
/*
file 1.txt on localhost contains text: 1
file 2.txt on localhost contains text: 2
*/
function run($fp, $c, $u) {
if ($fp) {
fwrite($fp, "GET {$u} HTTP/1.0\r\nHost: localhost\r\nConnection:
{$c}\r\n\r\n");
$data = '';
while (!feof($fp)) {
$data .= fgets($fp);
}
return $data;
}
}
//trying to use keep-alive
$fp = stream_socket_client("tcp://localhost:80", $errno, $errstr, 30);
echo run($fp, "keep-alive", "/1.txt");
echo run($fp, "keep-alive", "/2.txt");
fclose($fp);
//trying to use close
$fp = stream_socket_client("tcp://localhost:80", $errno, $errstr, 30);
echo run($fp, "close", "/1.txt");
fclose($fp);
$fp = stream_socket_client("tcp://localhost:80", $errno, $errstr, 30);
echo run($fp, "close", "/2.txt");
fclose($fp);
Expected result:
----------------
HTTP/1.1 200 OK
Date: Tue, 24 May 2011 13:35:50 GMT
Server: Apache
Last-Modified: Tue, 24 May 2011 13:16:42 GMT
ETag: "3200000001c164-3-4a405662479e4"
Accept-Ranges: bytes
Content-Length: 3
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/plain
1
HTTP/1.1 200 OK
Date: Tue, 24 May 2011 13:35:50 GMT
Server: Apache
Last-Modified: Tue, 24 May 2011 13:16:42 GMT
ETag: "3200000001c164-3-4a405662479e4"
Accept-Ranges: bytes
Content-Length: 3
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/plain
2
HTTP/1.1 200 OK
Date: Tue, 24 May 2011 13:35:57 GMT
Server: Apache
Last-Modified: Tue, 24 May 2011 13:16:42 GMT
ETag: "3200000001c164-3-4a405662479e4"
Accept-Ranges: bytes
Content-Length: 3
Connection: close
Content-Type: text/plain
1
HTTP/1.1 200 OK
Date: Tue, 24 May 2011 13:35:58 GMT
Server: Apache
Last-Modified: Tue, 24 May 2011 13:16:53 GMT
ETag: "1700000001c166-1-4a40566ce2b4c"
Accept-Ranges: bytes
Content-Length: 1
Connection: close
Content-Type: text/plain
2
Actual result:
--------------
HTTP/1.1 200 OK
Date: Tue, 24 May 2011 13:35:50 GMT
Server: Apache
Last-Modified: Tue, 24 May 2011 13:16:42 GMT
ETag: "3200000001c164-3-4a405662479e4"
Accept-Ranges: bytes
Content-Length: 3
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/plain
1
HTTP/1.1 200 OK
Date: Tue, 24 May 2011 13:35:57 GMT
Server: Apache
Last-Modified: Tue, 24 May 2011 13:16:42 GMT
ETag: "3200000001c164-3-4a405662479e4"
Accept-Ranges: bytes
Content-Length: 3
Connection: close
Content-Type: text/plain
1
HTTP/1.1 200 OK
Date: Tue, 24 May 2011 13:35:58 GMT
Server: Apache
Last-Modified: Tue, 24 May 2011 13:16:53 GMT
ETag: "1700000001c166-1-4a40566ce2b4c"
Accept-Ranges: bytes
Content-Length: 1
Connection: close
Content-Type: text/plain
2
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=54917&edit=1