1 | <?php |
||
9 | class CURLPool |
||
10 | { |
||
11 | /** |
||
12 | * Options. |
||
13 | * @var CoOption |
||
14 | */ |
||
15 | private $options; |
||
16 | |||
17 | /** |
||
18 | * cURL multi handle. |
||
19 | * @var resource |
||
20 | */ |
||
21 | private $mh; |
||
22 | |||
23 | /** |
||
24 | * cURL handles those have not been dispatched. |
||
25 | * @var array |
||
26 | */ |
||
27 | private $queue = []; |
||
28 | |||
29 | /** |
||
30 | * cURL handles those have been already dispatched. |
||
31 | * @var array |
||
32 | */ |
||
33 | private $added = []; |
||
34 | |||
35 | /** |
||
36 | * React Deferreds. |
||
37 | * @var Deferred |
||
38 | */ |
||
39 | private $deferreds = []; |
||
40 | |||
41 | /** |
||
42 | * Constructor. |
||
43 | * Initialize cURL multi handle. |
||
44 | * @param CoOption $options |
||
45 | */ |
||
46 | 6 | public function __construct(CoOption $options) |
|
53 | |||
54 | /** |
||
55 | * Call curl_multi_add_handle() or push into queue. |
||
56 | * @param resource $ch |
||
57 | * @param Deferred $deferred |
||
58 | */ |
||
59 | 4 | public function addOrEnqueue($ch, $deferred = null) |
|
78 | |||
79 | /** |
||
80 | * Run curl_multi_exec() loop. |
||
81 | */ |
||
82 | 3 | public function wait() |
|
104 | |||
105 | /** |
||
106 | * Read completed cURL handles. |
||
107 | * @return array |
||
108 | */ |
||
109 | 3 | private function readEntries() |
|
125 | } |
||
126 |
PHP has two types of connecting operators (logical operators, and boolean operators):
and
&&
or
||
The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&
, or||
.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
die
introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.