You are here

private function PurgeHandlerCurl::execute_multi in Purge 7.2

Function to process multiple purges with curl.

1 call to PurgeHandlerCurl::execute_multi()
PurgeHandlerCurl::execute in includes/purge.class.inc
Funtion will determine what options are set and call the right execute function.

File

includes/purge.class.inc, line 564
Contains all class and interface definitions for Purge.

Class

PurgeHandlerCurl
Class definition for the Curl HTTP request library.

Code

private function execute_multi($purges, $handler_options) {
  $curl_purges = curl_multi_init();
  foreach ($purges as $purge_id => $purge) {
    $curl_requests[$purge_id] = $this
      ->get_curl_request($purge, $handler_options);
    curl_multi_add_handle($curl_purges, $curl_requests[$purge_id]);
  }

  // Execute the purge requests
  ob_start();
  $active = 0;
  $multi_result = $this
    ->multi_exec($curl_purges, $active);
  while ($active && $multi_result == CURLM_OK) {
    if (curl_multi_select($curl_purges) == -1) {
      usleep(100000);
    }
    $multi_result = $this
      ->multi_exec($curl_purges, $active);
  }
  ob_end_clean();

  // Result collection. Collects the http code returned for each url purged
  foreach ($purges as $purge_id => $purge) {
    $info = curl_getinfo($curl_requests[$purge_id]);
    $purges[$purge_id]['http_code'] = $info['http_code'];
    curl_multi_remove_handle($curl_purges, $curl_requests[$purge_id]);
  }
  curl_multi_close($curl_purges);
  return $purges;
}