1 | <?php |
||
9 | class CurlMulti |
||
10 | { |
||
11 | const MAX_CONNECTIONS = 10; |
||
12 | |||
13 | /** @var resource<curl_multi> */ |
||
14 | private $mh; |
||
15 | |||
16 | /** @var resource<curl>[] */ |
||
17 | private $unused = array(); |
||
18 | |||
19 | /** @var resource<curl>[] */ |
||
20 | private $using = array(); |
||
21 | |||
22 | /** @var CopyRequest[] */ |
||
23 | private $requests = array(); |
||
24 | |||
25 | /** @var CopyRequest[] */ |
||
26 | private $runningRequests = array(); |
||
27 | |||
28 | /** @var bool */ |
||
29 | private $permanent = true; |
||
30 | |||
31 | private $blackhole; |
||
32 | |||
33 | /** |
||
34 | * @param bool $permanent |
||
35 | */ |
||
36 | 5 | public function __construct($permanent = true) |
|
37 | { |
||
38 | 5 | static $mh_cache, $ch_cache; |
|
39 | |||
40 | 5 | if (!$permanent || !$mh_cache) { |
|
41 | 1 | $mh_cache = curl_multi_init(); |
|
42 | |||
43 | 1 | $ch_cache = array(); |
|
44 | 1 | for ($i = 0; $i < self::MAX_CONNECTIONS; ++$i) { |
|
45 | 1 | $ch = curl_init(); |
|
46 | 1 | Share::setup($ch); |
|
47 | 1 | $ch_cache[] = $ch; |
|
48 | } |
||
49 | } |
||
50 | |||
51 | 5 | $this->mh = $mh_cache; |
|
52 | 5 | $this->unused = $ch_cache; |
|
53 | 5 | $this->permanent = $permanent; |
|
54 | |||
55 | // for PHP<5.5 @see getFinishedResults() |
||
56 | 5 | $this->blackhole = fopen('php://temp', 'wb'); |
|
57 | 5 | } |
|
58 | |||
59 | /** |
||
60 | * @codeCoverageIgnore |
||
61 | */ |
||
62 | public function __destruct() |
||
79 | |||
80 | /** |
||
81 | * @param CopyRequest[] $requests |
||
82 | */ |
||
83 | 4 | public function setRequests(array $requests) |
|
87 | |||
88 | 5 | public function setupEventLoop() |
|
105 | 4 | ||
106 | 4 | public function wait() |
|
126 | 4 | ||
127 | 4 | public function getFinishedResults() |
|
159 | 5 | ||
160 | public function remain() |
||
164 | } |
||
165 |