Doc #80970 [NEW]: Default protocol_version in http resource context changed to HTTP 1.1 in PHP 8
| From: | zdenek dot crha at ui dot com | Date: | Mon, 19 Apr 2021 13:46:16 +0000 |
| Subject: | Doc #80970 [NEW]: Default protocol_version in http resource context changed to HTTP 1.1 in PHP 8 | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-18709@lists.php.net to get a copy of this message | ||
From: zdenek dot crha at ui dot com
Operating system: GNU/Linux Debian Bullseye
PHP version: 8.0.3
Package: HTTP related
Bug Type: Documentation Problem
Bug description:Default protocol_version in http resource context changed to HTTP 1.1 in PHP 8
Description:
------------
## Overview
The documentation at https://www.php.net/manual/en/context.http.php
states that the default
protocol_version is HTTP 1.0. This does not
seem to be true for PHP 8.0 anymore.
The changed default can be considered breaking change in some
applications.
## Package versions
PHP 7.4.16 (cli) (built: Mar 5 2021 08:39:16) ( NTS )
PHP 8.0.3 (cli) (built: Mar 5 2021 08:37:58) ( NTS )
## Description
We have a code that interleaves reading data from HTTP endpoint and its
processing. We use stream_select() to read partial response, do
processing and loop until connection is closed. Basically long-poll/SSE
client.
See extracted and minimized version in attachement.
The code worked fine in all PHP 7.4 versions but it started failing when
we started migration to PHP 8.0.
* the expected result is recored from PHP 7.4.16
* the actual result is recored from PHP 8.0.3
The root cause of the crash/failure seems to originate from changed
default value of protocol_version field used when creating http stream
resource.
The PHP 7.4 is setting the protocol_version to "1.0" while the PHP 8.0
is setting it to "1.1".
Different protocol version seems result into different processing and
failure to call stream_select() method on the resource due to cast
issues
I have checked the documentation at
https://www.php.net/manual/en/context.http.php
and the page still says
that the default protocol version is "1.0". I have tried to find any
information about the change in PHP 8.0 changelog but failed.
I think that either of following would resolve the issue:
* reverted default protocol_version back to HTTP 1.0
* fix stream_select() or related code to handle HTTP 1.1 resources
* document the change and mark it as breaking in PHP 8.0 changelog
Test script:
---------------
#!/usr/bin/env php
<?php
$context = stream_context_create(['http' => [ 'method' => 'GET'
]]);
if ($stream = fopen($argv[1] ?? 'http://www.php.net', 'r', false,
$context)) {
$read = [$stream];
$ignore = [];
do {
$count = stream_select($read, $ignore, $ignore, 5, 0);
if (is_int($count) && $count > 0 && false !== ($text =
fgets($stream))) {
printf("0x%s\n", bin2hex($text));
} else {
exit(1);
}
} while (true);
}
Expected result:
----------------
0x3c21444f43545950452068746d6c3e0a
0x3c68746d6c20786d6c6e733d22687474703a2f2f7777772e77332e6f72672f313939392f7868746d6c22206c616e673d22656e223e0a
0x3c686561643e0a
0x0a
.... snip many lines ....
0x0a
0x3c2f626f64793e0a
0x3c2f68746d6c3e0a
Actual result:
--------------
PHP Warning: stream_select(): Cannot cast a filtered stream on this
system in /home/bin/http-poll-client on line 12
PHP Stack trace:
PHP 1. {main}() /home/bin/http-poll-client:0
PHP 2. stream_select($read = [0 => resource(6) of type (stream)],
$write = [], $except = [], $seconds = 5, $microseconds = 0)
/home/bin/http-poll-client:12
PHP Fatal error: Uncaught ValueError: No stream arrays were passed in
/home/bin/http-poll-client:12
Stack trace:
#0 /home/bin/http-poll-client(12): stream_select()
#1 {main}
thrown in /home/bin/http-poll-client on line 12
--
Edit bug report at https://bugs.php.net/bug.php?id=80970&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80970&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80970&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80970&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80970&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80970&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80970&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80970&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80970&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80970&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80970&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80970&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80970&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80970&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80970&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80970&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80970&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80970&r=mysqlcfg