Doc #80970 [Opn]: Default protocol_version in http resource context changed to HTTP 1.1 in PHP 8

From: Date: Mon, 19 Apr 2021 14:33:37 +0000
Subject: Doc #80970 [Opn]: Default protocol_version in http resource context changed to HTTP 1.1 in PHP 8
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-18710@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80970&edit=1 ID: 80970 Updated by: cmb@php.net Reported by: zdenek dot crha at ui dot com Summary: Default protocol_version in http resource context changed to HTTP 1.1 in PHP 8 Status: Open Type: Documentation Problem Package: HTTP related Operating System: GNU/Linux Debian Bullseye PHP Version: 8.0.3 Block user comment: N Private report: N New Comment: The actual problem is that the server responds with Transfer-Encoding: chunked for HTTP/1.1 requests, and the dechunking is implemented via a filter. Previous Comments: ------------------------------------------------------------------------ [2021-04-19 13:46:15] zdenek dot crha at ui dot com 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 this bug report at https://bugs.php.net/bug.php?id=80970&edit=1

« previous php.doc.bugs (#18710) next »