1--TEST--
2Test CURLMOPT_PUSHFUNCTION
3--CREDITS--
4Davey Shafik
5Kévin Dunglas
6--EXTENSIONS--
7curl
8--SKIPIF--
9<?php
10include 'skipif-nocaddy.inc';
11
12$curl_version = curl_version();
13if ($curl_version['version_number'] < 0x080100) {
14    exit("skip: test may crash with curl < 8.1.0");
15}
16?>
17--FILE--
18<?php
19$callback = function($parent_ch, $pushed_ch, array $headers) {
20	return CURL_PUSH_OK;
21};
22
23$mh = curl_multi_init();
24
25curl_multi_setopt($mh, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
26curl_multi_setopt($mh, CURLMOPT_PUSHFUNCTION, $callback);
27
28$ch = curl_init();
29curl_setopt($ch, CURLOPT_URL, "https://localhost/serverpush");
30curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
31curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
32
33curl_multi_add_handle($mh, $ch);
34
35$responses = [];
36$active = null;
37do {
38    $status = curl_multi_exec($mh, $active);
39
40    do {
41        $info = curl_multi_info_read($mh);
42        if (false !== $info && $info['msg'] == CURLMSG_DONE) {
43            $handle = $info['handle'];
44            if ($handle !== null) {
45		        $responses[] = curl_multi_getcontent($info['handle']);
46                curl_multi_remove_handle($mh, $handle);
47                curl_close($handle);
48            }
49        }
50    } while ($info);
51} while (count($responses) !== 2);
52
53curl_multi_close($mh);
54
55sort($responses);
56print_r($responses);
57?>
58--EXPECT--
59Array
60(
61    [0] => main response
62    [1] => pushed response
63)
64