1 | <?php |
||
17 | class ReactAwareCurlFactory implements CurlFactoryInterface |
||
18 | { |
||
19 | private $eventLoop; |
||
20 | private $logger; |
||
21 | private $factory; |
||
22 | private $count; |
||
23 | |||
24 | /** @var CurlMultiHandler */ |
||
25 | private $handler; |
||
26 | |||
27 | /** @var TimerInterface|null */ |
||
28 | private $timer; |
||
29 | |||
30 | /** |
||
31 | * ReactAwareCurlFactory wraps an instance of CurlFactory and keeps |
||
32 | * track of active curl handles. When there are active curl handles it starts |
||
33 | * a periodic task on the React event loop that calls CurlMultiHandler::tick() |
||
34 | * allowing tasks in the Guzzle task queue to be processed. |
||
35 | * The periodic task is stopped when there are no more active curl handles |
||
36 | * and the Guzzle task queue is empty. |
||
37 | * |
||
38 | * @param LoopInterface $eventLoop |
||
39 | * @param CurlFactory $curlFactory |
||
40 | * @param LoggerInterface|null $logger |
||
41 | */ |
||
42 | public function __construct( |
||
54 | |||
55 | public function setHandler(CurlMultiHandler $handler) |
||
59 | |||
60 | public function getHandler() : CurlMultiHandler |
||
64 | |||
65 | /** |
||
66 | * {@inheritDoc} |
||
67 | */ |
||
68 | public function create(RequestInterface $request, array $options) |
||
74 | |||
75 | /** |
||
76 | * {@inheritDoc} |
||
77 | */ |
||
78 | public function release(EasyHandle $easy) |
||
84 | |||
85 | public function tick() |
||
97 | |||
98 | public function isTimerActive() : bool |
||
106 | |||
107 | public function noMoreWork() : bool |
||
111 | |||
112 | protected function noActiveHandles() : bool |
||
116 | |||
117 | protected function queueIsEmpty() : bool |
||
121 | |||
122 | protected function incrementCount() |
||
130 | |||
131 | protected function decrementCount() |
||
135 | |||
136 | protected function startTimer() |
||
144 | |||
145 | protected function stopTimer() |
||
154 | } |
||
155 |