xref: /php-src/ext/standard/tests/http/bug65634.phpt (revision f39b5c4c)
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?>
53--EXPECTF--
54HTTP/1.0, default behaviour:
55GET / HTTP/1.0
56Host: %s:%d
57Connection: close
58
59HTTP/1.0, connection: close:
60GET / HTTP/1.0
61Host: %s:%d
62Connection: close
63
64HTTP/1.0, connection: keep-alive:
65GET / HTTP/1.0
66Host: %s:%d
67Connection: keep-alive
68
69HTTP/1.1, default behaviour:
70GET / HTTP/1.1
71Host: %s:%d
72Connection: close
73
74HTTP/1.1, connection: close:
75GET / HTTP/1.1
76Host: %s:%d
77Connection: close
78
79HTTP/1.1, connection: keep-alive:
80GET / HTTP/1.1
81Host: %s:%d
82Connection: keep-alive
83