#45540 [Opn->Csd]: stream_context_create creates bad http request
| From: | lbarnaud@php.net | Date: | Mon, 28 Jul 2008 19:11:44 +0000 |
| Subject: | #45540 [Opn->Csd]: stream_context_create creates bad http request | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-127350@lists.php.net to get a copy of this message | ||
ID: 45540
Updated by: lbarnaud@php.net
Reported By: jdespatis at yahoo dot fr
-Status: Open
+Status: Closed
Bug Type: Streams related
Operating System: Linux Kubuntu
PHP Version: 5.2.6
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
The server replies with a Location header, the HTTP wrapper
automatically redirect, and that second request was effectively invalid
(the request was sent as POST without Content-Length and post data).
Previous Comments:
------------------------------------------------------------------------
[2008-07-27 08:37:26] jdespatis at yahoo dot fr
Well, i can give you a self-contained reproducing script:
http://www.despatis.com/php/stream.phps
But, it's impossible for me to avoid the use of POST, because this bug
occurs on a http connection..
To run the bug, you just do in the command line (so using php cli):
$ php stream.php
I get the following result, you'll need a sniffer to see that data sent
to http server is completely weird
token :
AIwbFASbZooZXBAePnl4eayE1cZvRWbvOtzQTC-vRR-lkp1r3ijZ7AxoSIzuslTVmufPznylay34ryUPdLRMGh61cidHS29Z7NkKqLVYr2JdNY4iKN0qoVB2MSaV2rmumH_ZJTo3gp7Or0IJlaiMiNEs2R5aNllOYg
Array
(
[type] => 2
[message] =>
file_get_contents(http://uploads.gdata.youtube.com/feeds/api/users/bigbluezen/uploads):
failed to open stream: HTTP request failed! HTTP/1.0 411 Length
Required
[file] =>
/home/enzo/projects/lacartoonerie/download/modules/stream.php
[line] => 101
)
------------------------------------------------------------------------
[2008-07-20 11:10:00] jani@php.net
Ok. Now can you provide a proper self-contained reproducing script. One
that starts with <?php, ends with ?> and can be run on the command line.
ie. no POST required..
------------------------------------------------------------------------
[2008-07-18 16:45:03] jdespatis at yahoo dot fr
enzo@poseidon:~$ cat php-5.2.6/config.nice
#! /bin/sh
#
# Created by configure
'./configure' \
'--enable-sockets' \
'--enable-soap' \
'--with-mysql' \
'--enable-mbstring' \
'--enable-ftp' \
'--with-zlib' \
'--with-openssl' \
'--prefix=/home/enzo/divers/php_compil/' \
'--exec-prefix=/home/enzo/divers/php_compil/' \
'--disable-short-tags' \
"$@"
------------------------------------------------------------------------
[2008-07-18 16:05:44] jani@php.net
For the second time: What was the configure line you used to build PHP?
------------------------------------------------------------------------
[2008-07-18 12:23:17] jdespatis at yahoo dot fr
And to help to diagnose the problem
i can perfectly make this script work if I code the stream by my own
for example, I replace stream_context_create by some code using
fsockopen, all works perfectly ... (i really think stream_context_create
leaves some \r \n in some special case ...)
$context = stream_context_create($opts);
$buff =
@file_get_contents("http://uploads.gdata.youtube.com/feeds/api/users/$username/uploads",
false, $context);
by
$fp = fsockopen("uploads.gdata.youtube.com", 80, $errno, $errstr, 30);
if (!$fp) {
return "Youtube unreachable $errstr ($errno)";
}
$out = "POST /feeds/api/users/$username/uploads HTTP/1.0\r\n";
$out .= "Host: uploads.gdata.youtube.com\r\n";
$out .= "Content-Length: " . strlen($opts["http"]["content"]
."\r\n";
$out .= "Connection: Close\r\n";
$out .= $opts["http"]["header"];
$out .= "\r\n";
$out .= $opts["http"]["content"];
fwrite($fp, $out);
$buff = "";
while (!feof($fp)) {
$buff .= fgets($fp, 4096);
}
fclose($fp);
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/45540
--
Edit this bug report at http://bugs.php.net/?id=45540&edit=1