You are here

function need_two_good_results in HTTP Parallel Request & Threading Library 7

Same name and namespace in other branches
  1. 6 examples/httprl.examples.php \need_two_good_results()
1 string reference to 'need_two_good_results'
httprl.examples.php in examples/httprl.examples.php
HTTP Parallel Request Library code examples.

File

examples/httprl.examples.php, line 326
HTTP Parallel Request Library code examples.

Code

function need_two_good_results($id, &$responses) {
  static $counter = 0;
  foreach ($responses as $id => &$result) {

    // Skip if we got a 200 or 206.
    if ($result->code == 200 || $result->code == 206) {
      $counter += 1;
      continue;
    }
    if ($result->status == 'Done.') {
      continue;
    }
    if ($counter >= 2) {

      // Set the code to request was aborted.
      $result->code = HTTPRL_REQUEST_ABORTED;
      $result->error = 'Software caused connection abort.';

      // Set status to done and set timeout.
      $result->status = 'Done.';
      $result->options['timeout'] -= $result->running_time;

      // Close the file pointer and remove from the stream from the array.
      fclose($result->fp);
      unset($result->fp);
    }
  }
}