dépôts
/
lhc
/
web
/
wiklou.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge "Show dimensions in TraditionalImageGallery"
[lhc/web/wiklou.git]
/
includes
/
libs
/
MultiHttpClient.php
diff --git
a/includes/libs/MultiHttpClient.php
b/includes/libs/MultiHttpClient.php
index
a870204
..
e9922b9
100644
(file)
--- a/
includes/libs/MultiHttpClient.php
+++ b/
includes/libs/MultiHttpClient.php
@@
-20,6
+20,10
@@
* @file
*/
* @file
*/
+use Psr\Log\LoggerAwareInterface;
+use Psr\Log\LoggerInterface;
+use Psr\Log\NullLogger;
+
/**
* Class to handle concurrent HTTP requests
*
/**
* Class to handle concurrent HTTP requests
*
@@
-42,7
+46,7
@@
* @author Aaron Schulz
* @since 1.23
*/
* @author Aaron Schulz
* @since 1.23
*/
-class MultiHttpClient {
+class MultiHttpClient
implements LoggerAwareInterface
{
/** @var resource */
protected $multiHandle = null; // curl_multi handle
/** @var string|null SSL certificates path */
/** @var resource */
protected $multiHandle = null; // curl_multi handle
/** @var string|null SSL certificates path */
@@
-59,6
+63,8
@@
class MultiHttpClient {
protected $proxy;
/** @var string */
protected $userAgent = 'wikimedia/multi-http-client v1.0';
protected $proxy;
/** @var string */
protected $userAgent = 'wikimedia/multi-http-client v1.0';
+ /** @var LoggerInterface */
+ protected $logger;
/**
* @param array $options
/**
* @param array $options
@@
-78,13
+84,17
@@
class MultiHttpClient {
}
}
static $opts = [
}
}
static $opts = [
- 'connTimeout', 'reqTimeout', 'usePipelining', 'maxConnsPerHost', 'proxy', 'userAgent'
+ 'connTimeout', 'reqTimeout', 'usePipelining', 'maxConnsPerHost',
+ 'proxy', 'userAgent', 'logger'
];
foreach ( $opts as $key ) {
if ( isset( $options[$key] ) ) {
$this->$key = $options[$key];
}
}
];
foreach ( $opts as $key ) {
if ( isset( $options[$key] ) ) {
$this->$key = $options[$key];
}
}
+ if ( $this->logger === null ) {
+ $this->logger = new NullLogger;
+ }
}
/**
}
/**
@@
-162,6
+172,7
@@
class MultiHttpClient {
} elseif ( !isset( $req['url'] ) ) {
throw new Exception( "Request has no 'url' field set." );
}
} elseif ( !isset( $req['url'] ) ) {
throw new Exception( "Request has no 'url' field set." );
}
+ $this->logger->debug( "{$req['method']}: {$req['url']}" );
$req['query'] = isset( $req['query'] ) ? $req['query'] : [];
$headers = []; // normalized headers
if ( isset( $req['headers'] ) ) {
$req['query'] = isset( $req['query'] ) ? $req['query'] : [];
$headers = []; // normalized headers
if ( isset( $req['headers'] ) ) {
@@
-215,7
+226,7
@@
class MultiHttpClient {
// Wait (if possible) for available work...
if ( $active > 0 && $mrc == CURLM_OK ) {
if ( curl_multi_select( $chm, 10 ) == -1 ) {
// Wait (if possible) for available work...
if ( $active > 0 && $mrc == CURLM_OK ) {
if ( curl_multi_select( $chm, 10 ) == -1 ) {
- // PHP bug 63411; http://curl.haxx.se/libcurl/c/curl_multi_fdset.html
+ // PHP bug 63411; http
s
://curl.haxx.se/libcurl/c/curl_multi_fdset.html
usleep( 5000 ); // 5ms
}
}
usleep( 5000 ); // 5ms
}
}
@@
-235,6
+246,8
@@
class MultiHttpClient {
if ( function_exists( 'curl_strerror' ) ) {
$req['response']['error'] .= " " . curl_strerror( $errno );
}
if ( function_exists( 'curl_strerror' ) ) {
$req['response']['error'] .= " " . curl_strerror( $errno );
}
+ $this->logger->warning( "Error fetching URL \"{$req['url']}\": " .
+ $req['response']['error'] );
}
} else {
$req['response']['error'] = "(curl error: no status set)";
}
} else {
$req['response']['error'] = "(curl error: no status set)";
@@
-420,6
+433,15
@@
class MultiHttpClient {
return $this->multiHandle;
}
return $this->multiHandle;
}
+ /**
+ * Register a logger
+ *
+ * @param LoggerInterface
+ */
+ public function setLogger( LoggerInterface $logger ) {
+ $this->logger = $logger;
+ }
+
function __destruct() {
if ( $this->multiHandle ) {
curl_multi_close( $this->multiHandle );
function __destruct() {
if ( $this->multiHandle ) {
curl_multi_close( $this->multiHandle );