From db2d4b670983df43686c4c1a671369d8ebcaaf82 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niklas=20Laxstr=C3=B6m?= Date: Wed, 13 May 2015 11:38:21 +0200 Subject: [PATCH] Fix MultiHttpClient to return correct errors Bug: T89758 Change-Id: Ia1f1986d150df1a9f463d48f1a914a04608550f8 --- includes/libs/MultiHttpClient.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/includes/libs/MultiHttpClient.php b/includes/libs/MultiHttpClient.php index 16e0d4fcca..f5d6fe41c9 100644 --- a/includes/libs/MultiHttpClient.php +++ b/includes/libs/MultiHttpClient.php @@ -189,6 +189,7 @@ class MultiHttpClient { // @TODO: use a per-host rolling handle window (e.g. CURLMOPT_MAX_HOST_CONNECTIONS) $batches = array_chunk( $indexes, $this->maxConnsPerHost ); + $infos = array(); foreach ( $batches as $batch ) { // Attach all cURL handles for this batch @@ -201,6 +202,10 @@ class MultiHttpClient { // Do any available work... do { $mrc = curl_multi_exec( $chm, $active ); + $info = curl_multi_info_read( $chm ); + if ( $info !== false ) { + $infos[(int)$info['handle']] = $info; + } } while ( $mrc == CURLM_CALL_MULTI_PERFORM ); // Wait (if possible) for available work... if ( $active > 0 && $mrc == CURLM_OK ) { @@ -216,10 +221,18 @@ class MultiHttpClient { foreach ( $reqs as $index => &$req ) { $ch = $handles[$index]; curl_multi_remove_handle( $chm, $ch ); - if ( curl_errno( $ch ) !== 0 ) { - $req['response']['error'] = "(curl error: " . - curl_errno( $ch ) . ") " . curl_error( $ch ); + + $info = $infos[(int)$ch]; + + $errno = $info['result']; + if ( $errno !== 0 ) { + $req['response']['error'] = "(curl error: $errno)"; + + if ( version_compare( PHP_VERSION, '5.5.0' ) >= 0 ) { + $req['response']['error'] .= " " . curl_strerror( $errno ); + } } + // For convenience with the list() operator $req['response'][0] = $req['response']['code']; $req['response'][1] = $req['response']['reason']; -- 2.20.1