xref: /PHP-8.2/ext/standard/tests/http/bug65634.phpt (revision 95f25837)
1--TEST--
2Bug #65634 (HTTP wrapper is very slow with protocol_version 1.1)
3--INI--
4allow_url_fopen=1
5--SKIPIF--
6<?php require 'server.inc'; http_server_skipif(); ?>
7--FILE--
8<?php
9require 'server.inc';
10
11function do_test($version, $connection) {
12    $options = [
13        'http' => [
14            'protocol_version' => $version,
15        ],
16    ];
17
18    if ($connection) {
19        $options['http']['header'] = "Connection: $connection";
20    }
21
22    $ctx = stream_context_create($options);
23
24    $responses = ["data://text/plain,HTTP/$version 204 No Content\r\n\r\n"];
25    ['pid' => $pid, 'uri' => $uri] = http_server($responses, $output);
26
27    $fd = fopen($uri, 'rb', false, $ctx);
28    fseek($output, 0, SEEK_SET);
29    echo stream_get_contents($output);
30
31    http_server_kill($pid);
32}
33
34echo "HTTP/1.0, default behaviour:\n";
35do_test('1.0', null);
36
37echo "HTTP/1.0, connection: close:\n";
38do_test('1.0', 'close');
39
40echo "HTTP/1.0, connection: keep-alive:\n";
41do_test('1.0', 'keep-alive');
42
43echo "HTTP/1.1, default behaviour:\n";
44do_test('1.1', null);
45
46echo "HTTP/1.1, connection: close:\n";
47do_test('1.1', 'close');
48
49echo "HTTP/1.1, connection: keep-alive:\n";
50do_test('1.1', 'keep-alive');
51
52--EXPECTF--
53HTTP/1.0, default behaviour:
54GET / HTTP/1.0
55Host: %s:%d
56Connection: close
57
58HTTP/1.0, connection: close:
59GET / HTTP/1.0
60Host: %s:%d
61Connection: close
62
63HTTP/1.0, connection: keep-alive:
64GET / HTTP/1.0
65Host: %s:%d
66Connection: keep-alive
67
68HTTP/1.1, default behaviour:
69GET / HTTP/1.1
70Host: %s:%d
71Connection: close
72
73HTTP/1.1, connection: close:
74GET / HTTP/1.1
75Host: %s:%d
76Connection: close
77
78HTTP/1.1, connection: keep-alive:
79GET / HTTP/1.1
80Host: %s:%d
81Connection: keep-alive
82