src/Moar/Net/Http/Request.php
public static function parallelSubmit ($requests) {
    $handles = array();
    $mh = curl_multi_init();

    // make a curl handle for each request
    foreach ($requests as $req) {
      $ch = $req->createCurlRequest();
      $handles[(string) $ch] = $req;
      curl_multi_add_handle($mh, $ch);
    }

    $reqsRunning = 0;

    // fire off initial requests
    do {
      $status = curl_multi_exec($mh, $reqsRunning);
    } while (CURLM_CALL_MULTI_PERFORM == $status);

    // process the requests
    while ($reqsRunning && CURLM_OK == $status) {
      // wait to be woken up by network activity
      $selectReady = curl_multi_select($mh);

      if ($selectReady > 0) {
        // one or more requests are finished
        while ($info = curl_multi_info_read($mh)) {
          self::handleMultiResponse($info, $mh, $handles);
        }
      } //end if selectReady

      if (-1 != $selectReady) {
        // continue processing
        do {
          $status = curl_multi_exec($mh, $reqsRunning);
        } while (CURLM_CALL_MULTI_PERFORM == $status);
      }
    } //end while requests to process

    // check for critical failure
    if (CURLM_OK != $status) {
      throw new Exception(
          "Fatal error [{$status}] processing multiple requests", $status);
    }

    // any remaining results should be ready now
    while ($handles && ($info = curl_multi_info_read($mh))) {
      self::handleMultiResponse($info, $mh, $handles);
    }

    curl_multi_close($mh);
    return $requests;
  }
public static function parallelSubmit ($requests) {
    $handles = array();
    $mh = curl_multi_init();

    // make a curl handle for each request
    foreach ($requests as $req) {
      $ch = $req->createCurlRequest();
      $handles[(string) $ch] = $req;
      curl_multi_add_handle($mh, $ch);
    }

    $reqsRunning = 0;

    // fire off initial requests
    do {
      $status = curl_multi_exec($mh, $reqsRunning);
    } while (CURLM_CALL_MULTI_PERFORM == $status);

    // process the requests
    while ($reqsRunning && CURLM_OK == $status) {
      // wait to be woken up by network activity
      $selectReady = curl_multi_select($mh);

      if ($selectReady > 0) {
        // one or more requests are finished
        while ($info = curl_multi_info_read($mh)) {
          self::handleMultiResponse($info, $mh, $handles);
        }
      } //end if selectReady

      if (-1 != $selectReady) {
        // continue processing
        do {
          $status = curl_multi_exec($mh, $reqsRunning);
        } while (CURLM_CALL_MULTI_PERFORM == $status);
      }
    } //end while requests to process

    // check for critical failure
    if (CURLM_OK != $status) {
      throw new Exception(
          "Fatal error [{$status}] processing multiple requests", $status);
    }

    // any remaining results should be ready now
    while ($handles && ($info = curl_multi_info_read($mh))) {
      self::handleMultiResponse($info, $mh, $handles);
    }

    curl_multi_close($mh);
    return $requests;
  }
public static function parallelSubmit ( $ requests ) { $ handles = array ( ) ; $ mh = curl_multi_init ( ) ; // make a curl handle for each request foreach ( $ requests as $ req ) { $ ch = $ req -> createCurlRequest ( ) ; $ handles [ ( string ) $ ch ] = $ req ; curl_multi_add_handle ( $ mh , $ ch ) ; } $ reqsRunning = 0 ; // fire off initial requests do { $ status = curl_multi_exec ( $ mh , $ reqsRunning ) ; } while ( CURLM_CALL_MULTI_PERFORM == $ status ) ; // process the requests while ( $ reqsRunning && CURLM_OK == $ status ) { // wait to be woken up by network activity $ selectReady = curl_multi_select ( $ mh ) ; if ( $ selectReady > 0 ) { // one or more requests are finished while ( $ info = curl_multi_info_read ( $ mh ) ) { self :: handleMultiResponse ( $ info , $ mh , $ handles ) ; } } //end if selectReady if ( - 1 != $ selectReady ) { // continue processing do { $ status = curl_multi_exec ( $ mh , $ reqsRunning ) ; } while ( CURLM_CALL_MULTI_PERFORM == $ status ) ; } } //end while requests to process // check for critical failure if ( CURLM_OK != $ status ) { throw new Exception ( "Fatal error [{$status}] processing multiple requests" , $ status ) ; } // any remaining results should be ready now while ( $ handles && ( $ info = curl_multi_info_read ( $ mh ) ) ) { self :: handleMultiResponse ( $ info , $ mh , $ handles ) ; } curl_multi_close ( $ mh ) ; return $ requests ; }
Submit a group of requests in parallel.

Uses the curl_multi_exec engine to fire off several requests in parallel
and waits for all responses to finish before returing the collective
results.

@param array $requests List of requests to submit
@return array List of submitted requests
@throws Exception If a fatal multi error occurs.
Submit a group of requests in parallel .