Edit report at http://bugs.php.net/bug.php?id=51268&edit=1
ID: 51268
User updated by: arlo at arlomedia dot com
Reported by: arlo at arlomedia dot com
Summary: fsockopen+fread behaves differently with port 443 vs.
port 80
Status: Bogus
Type: Bug
Package: Network related
Operating System: Red Hat Linux
PHP Version: 5.2.13
New Comment:
This comment doesn't address my issue. The issue is that the function
behaves
differently depending on the port used for the remote connection. Over
port 80, I
requested 4096 bytes of data from fread and got 4096 bytes of data, but
over port
443 I only got the headers. Why is this not consistent?
The practical result is that I set up a utility using port 80 on a
testing server,
then when I tried to implement it on port 443 on a development server, I
had to
troubleshoot and then rework the code because of this undocumented
difference.
Previous Comments:
------------------------------------------------------------------------
[2010-05-19 15:36:37] [email protected]
Quoting documentation:
Warning
When reading from anything that is not a regular local file, such as
streams returned when reading remote files or from popen() and
fsockopen(), reading will stop after a packet is available. This means
that you should collect the data together in chunks as shown in the
examples below.
------------------------------------------------------------------------
[2010-03-11 01:49:48] arlo at arlomedia dot com
Description:
------------
If I open a network connection with fsockopen on port 80, then read the
first
chunk of the response with fread, I receive the response headers plus
enough of
the response body to fulfill the read length that I requested.
However, if I do the same thing over port 443, I receive only the
response headers
in my initial fread command, regardless of their length. I don't receive
any of
the response body until I call fread again.
The script below demonstrates this. If you run it as shown, you will see
the
header plus part of the body as response 1, and a continuation of the
body as
response 2. But if you change $connection_port to 443, you will see only
the
header as response 1, with the body starting at response 2.
I repeated this issue on one server running PHP 5.2.13 and another
running 5.3.0.
Test script:
---------------
<?php
$connection_port = 80;
$source_domain = "www.msgen.com";
$source_path = "/assembled/home.html";
$source_host = ($connection_port == 443) ? "ssl://$source_domain" :
$source_domain ;
$request = "GET /$source_path HTTP/1.0\nHost:
$source_domain\nConnection: close\n\n";
$socket = fsockopen($source_host, $connection_port, $error_number,
$error_string);
fputs($socket, $request);
$response_1 = fread($socket, 4096);
$response_2 = fread($socket, 4096);
print "response 1:<br />\n".htmlentities($response_1);
print "<br /><br />\n";
print "response 2:<br />\n".htmlentities($response_2);
?>
Expected result:
----------------
I would expect fread to return the same results regardless of the port
used for
fsockopen.
Actual result:
--------------
The first instance of fread stops at the end of the headers when using
port 443.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=51268&edit=1