1--TEST--
2array curl_multi_get_handles ( CurlMultiHandle $mh );
3--EXTENSIONS--
4curl
5--FILE--
6<?php
7$urls = array(
8    "file://".__DIR__."/curl_testdata1.txt",
9    "file://".__DIR__."/curl_testdata2.txt",
10);
11
12$mh = curl_multi_init();
13$map = new WeakMap();
14
15foreach ($urls as $url) {
16    echo "Initializing {$url}.", PHP_EOL;
17    $ch = curl_init($url);
18    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
19    curl_multi_add_handle($mh, $ch);
20    printf("%d handles are attached\n", count(curl_multi_get_handles($mh)));
21    $map[$ch] = $url;
22}
23
24do {
25    $status = curl_multi_exec($mh, $active);
26    if ($status !== CURLM_OK) {
27        throw new \Exception(curl_multi_strerror(curl_multi_errno($mh)));
28    }
29
30    if ($active) {
31        $activity = curl_multi_select($mh);
32        if ($activity === -1) {
33            throw new \Exception(curl_multi_strerror(curl_multi_errno($mh)));
34        }
35    }
36
37    while (($info = curl_multi_info_read($mh)) !== false) {
38        if ($info['msg'] === CURLMSG_DONE) {
39            $handle = $info['handle'];
40            $url = $map[$handle];
41            echo "Request to {$url} finished.", PHP_EOL;
42            printf("%d handles are attached\n", count(curl_multi_get_handles($mh)));
43            curl_multi_remove_handle($mh, $handle);
44            printf("%d handles are attached\n", count(curl_multi_get_handles($mh)));
45
46            if ($info['result'] === CURLE_OK) {
47                echo "Success.", PHP_EOL;
48            } else {
49                echo "Failure.", PHP_EOL;
50            }
51        }
52    }
53} while ($active);
54
55printf("%d handles are attached\n", count(curl_multi_get_handles($mh)));
56
57?>
58--EXPECTF--
59Initializing %scurl_testdata1.txt.
601 handles are attached
61Initializing %scurl_testdata2.txt.
622 handles are attached
63Request to %scurl_testdata%d.txt finished.
642 handles are attached
651 handles are attached
66Success.
67Request to %scurl_testdata%d.txt finished.
681 handles are attached
690 handles are attached
70Success.
710 handles are attached
72