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