You are here

function background_process_http_request_process in Background Process 7

Same name and namespace in other branches
  1. 8 background_process.module \background_process_http_request_process()
  2. 6 background_process.module \background_process_http_request_process()
  3. 7.2 background_process.http.inc \background_process_http_request_process()

Process multiple http requests.

1 call to background_process_http_request_process()
background_process_determine_default_service_host in ./background_process.module
Determine host for current installation.

File

./background_process.module, line 1418

Code

function background_process_http_request_process(&$results, $options = array()) {
  $options += array(
    'timeout' => 30,
    'interval' => 0.01,
    'limit' => 0,
  );
  $interval = $options['interval'] * 1000000;
  $expire = time() + $options['timeout'];
  while ($results && time() < $expire) {
    $cnt = 0;
    $data_ready = FALSE;
    foreach ($results as $i => &$result) {
      if (isset($result->code)) {
        continue;
      }
      background_process_http_request_get_response($result);
      $data_ready = $data_ready || $result->data_ready ? TRUE : FALSE;
      $cnt++;
      if ($options['limit'] && $cnt >= $options['limit']) {
        break;
      }
    }
    if (!$cnt) {
      break;
    }
    if (!$data_ready) {
      usleep($interval);
    }
  }
}