Bug #54917 [NEW]: Incorrect behavior of the sockets functions when using HTTP-connections

From: Date: Tue, 24 May 2011 13:46:15 +0000
Subject: Bug #54917 [NEW]: Incorrect behavior of the sockets functions when using HTTP-connections
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-160930@lists.php.net to get a copy of this message
From:             
Operating system: Windows 7, Ubuntu 10.10
PHP version:      5.3SVN-2011-05-24 (snap)
Package:          Sockets related
Bug Type:         Bug
Bug description:Incorrect behavior of the sockets functions when using HTTP-connections

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 bug report at http://bugs.php.net/bug.php?id=54917&edit=1
-- 
Try a snapshot (PHP 5.2):            http://bugs.php.net/fix.php?id=54917&r=trysnapshot52
Try a snapshot (PHP 5.3):            http://bugs.php.net/fix.php?id=54917&r=trysnapshot53
Try a snapshot (trunk):              http://bugs.php.net/fix.php?id=54917&r=trysnapshottrunk
Fixed in SVN:                        http://bugs.php.net/fix.php?id=54917&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=54917&r=needdocs
Fixed in release:                    http://bugs.php.net/fix.php?id=54917&r=alreadyfixed
Need backtrace:                      http://bugs.php.net/fix.php?id=54917&r=needtrace
Need Reproduce Script:               http://bugs.php.net/fix.php?id=54917&r=needscript
Try newer version:                   http://bugs.php.net/fix.php?id=54917&r=oldversion
Not developer issue:                 http://bugs.php.net/fix.php?id=54917&r=support
Expected behavior:                   http://bugs.php.net/fix.php?id=54917&r=notwrong
Not enough info:                     http://bugs.php.net/fix.php?id=54917&r=notenoughinfo
Submitted twice:                     http://bugs.php.net/fix.php?id=54917&r=submittedtwice
register_globals:                    http://bugs.php.net/fix.php?id=54917&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=54917&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=54917&r=dst
IIS Stability:                       http://bugs.php.net/fix.php?id=54917&r=isapi
Install GNU Sed:                     http://bugs.php.net/fix.php?id=54917&r=gnused
Floating point limitations:          http://bugs.php.net/fix.php?id=54917&r=float
No Zend Extensions:                  http://bugs.php.net/fix.php?id=54917&r=nozend
MySQL Configuration Error:           http://bugs.php.net/fix.php?id=54917&r=mysqlcfg



Thread (2 messages)

« previous php.bugs (#160930) next »