protected function execCurl($handle) {
    if (empty($this->multi)) {
      $multi = curl_multi_init();
      $this->multi = $multi;
      // fwrite(STDOUT, "Creating MULTI handle.\n");
    }
    else {
      // fwrite(STDOUT, "Reusing MULTI handle.\n");
      $multi = $this->multi;
    }
    curl_multi_add_handle($multi, $handle);

    // Initialize all of the listeners
    $active = NULL;
    do {
      while (($mrc = curl_multi_exec($multi, $active)) == CURLM_CALL_MULTI_PERFORM);
      if ($active && curl_multi_select($multi) === -1) {
        // Sleep when a select returns a -1.
        // https://bugs.php.net/bug.php?id=61141
        usleep(250);
      }
    } while ($active && $mrc == CURLM_OK);

    curl_multi_remove_handle($multi, $handle);
    //curl_multi_close($multi);

    return TRUE;
  }
protected function execCurl($handle) {
    if (empty($this->multi)) {
      $multi = curl_multi_init();
      $this->multi = $multi;
      // fwrite(STDOUT, "Creating MULTI handle.\n");
    }
    else {
      // fwrite(STDOUT, "Reusing MULTI handle.\n");
      $multi = $this->multi;
    }
    curl_multi_add_handle($multi, $handle);

    // Initialize all of the listeners
    $active = NULL;
    do {
      while (($mrc = curl_multi_exec($multi, $active)) == CURLM_CALL_MULTI_PERFORM);
      if ($active && curl_multi_select($multi) === -1) {
        // Sleep when a select returns a -1.
        // https://bugs.php.net/bug.php?id=61141
        usleep(250);
      }
    } while ($active && $mrc == CURLM_OK);

    curl_multi_remove_handle($multi, $handle);
    //curl_multi_close($multi);

    return TRUE;
  }
protected function execCurl ( $ handle ) { if ( empty ( $ this -> multi ) ) { $ multi = curl_multi_init ( ) ; $ this -> multi = $ multi ; // fwrite(STDOUT, "Creating MULTI handle.\n"); } else { // fwrite(STDOUT, "Reusing MULTI handle.\n"); $ multi = $ this -> multi ; } curl_multi_add_handle ( $ multi , $ handle ) ; // Initialize all of the listeners $ active = NULL ; do { while ( ( $ mrc = curl_multi_exec ( $ multi , $ active ) ) == CURLM_CALL_MULTI_PERFORM ) ; if ( $ active && curl_multi_select ( $ multi ) === - 1 ) { // Sleep when a select returns a -1. // https://bugs.php.net/bug.php?id=61141 usleep ( 250 ) ; } } while ( $ active && $ mrc == CURLM_OK ) ; curl_multi_remove_handle ( $ multi , $ handle ) ; //curl_multi_close($multi); return TRUE ; }
Poor man's connection pooling.

Instead of using curl_exec(), we use curl_multi_* to
handle the processing The CURL multi library tracks connections, and
basically provides connection sharing across requests. So two requests made to
the same server will use the same connection (even when they are executed
separately) assuming that the remote server supports this.

We've noticed that this improves performance substantially, especially since
SSL requests only require the SSL handshake once.

@param resource $handle
A CURL handle from curl_init().
@retval boolean
@return boolean
Returns a boolean value indicating whether or not CURL could process the
request.
Poor man s connection pooling .