1 | <?php |
||
11 | final class MysqliAsync implements \Countable |
||
12 | { |
||
13 | private $queries = []; |
||
14 | private $processed = 0; |
||
15 | |||
16 | private static $instance; |
||
17 | private static $sleep = 0; |
||
18 | private static $usleep = 50000; |
||
19 | |||
20 | /** |
||
21 | * MysqliAsync constructor. |
||
22 | * Disabled to force singleton use. |
||
23 | */ |
||
24 | private function __construct() |
||
27 | |||
28 | /** |
||
29 | * @param string $query |
||
30 | * @param mysqli $cnx |
||
31 | * @return Promise |
||
32 | */ |
||
33 | public static function query(string $query, mysqli $cnx) |
||
45 | |||
46 | /** |
||
47 | * @return MysqliAsync |
||
48 | */ |
||
49 | public static function getInstance() |
||
57 | |||
58 | /** |
||
59 | * Poll every $wait seconds. |
||
60 | * To poll every 100ms, call pollEvery(0.100). |
||
61 | * |
||
62 | * @param float $wait |
||
63 | */ |
||
64 | public static function pollEvery(float $wait) |
||
75 | |||
76 | /** |
||
77 | * @param array $query |
||
78 | * @return mysqli |
||
79 | */ |
||
80 | private function getConnection(array $query): mysqli |
||
84 | |||
85 | /** |
||
86 | * @param array $query |
||
87 | * @return PromiseInterface |
||
88 | */ |
||
89 | private function getPromise(array $query): PromiseInterface |
||
93 | |||
94 | /** |
||
95 | * Resets current pool. |
||
96 | */ |
||
97 | private function reset() |
||
102 | |||
103 | /** |
||
104 | * Wait for pending queries to complete. |
||
105 | */ |
||
106 | private function wait() |
||
144 | |||
145 | /** |
||
146 | * @inheritDoc |
||
147 | */ |
||
148 | public function count() |
||
152 | } |
||
153 |