Get the data from the multi handle
protected function perform() {
// @codeCoverageIgnoreStart
// Weird things can happen when making HTTP requests in __destruct methods
if (!$this->multiHandle) {
return;
}
// @codeCoverageIgnoreEnd
// If there are no requests to send, then exit from the function
if ($this->scope <= 0) {
if ($this
->count() == 0) {
return;
}
}
elseif (empty($this->requests[$this->scope])) {
return;
}
// Create the polling event external to the loop
$event = array(
'curl_multi' => $this,
);
$active = $this
->executeHandles();
while (1) {
$this
->processMessages();
// Exit the function if there are no more requests to send
if (!($scopedPolling = $this->scope <= 0 ? $this
->all() : $this->requests[$this->scope])) {
break;
}
// Notify each request as polling
$blocking = $total = 0;
foreach ($scopedPolling as $request) {
$event['request'] = $request;
$request
->dispatch(self::POLLING_REQUEST, $event);
++$total;
// The blocking variable just has to be non-falsey to block the loop
if ($request
->getParams()
->hasKey(self::BLOCKING)) {
++$blocking;
}
}
if ($blocking == $total) {
// Sleep to prevent eating CPU because no requests are actually pending a select call
usleep(500);
}
else {
// Select the curl handles until there is any activity on any of the open file descriptors
// See https://github.com/php/php-src/blob/master/ext/curl/multi.c#L170
$active = $this
->executeHandles(true, 0.02, $active);
}
}
}