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