From: Bryan Davis Date: Sat, 24 Oct 2015 22:05:21 +0000 (-0600) Subject: LoggerFactory: Only check for Psr\Log\LoggerInterface once X-Git-Tag: 1.31.0-rc.0~9230^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/password.php?a=commitdiff_plain;h=701b9a0dc8f84326b558059e7e0d70d671a828e3;p=lhc%2Fweb%2Fwiklou.git LoggerFactory: Only check for Psr\Log\LoggerInterface once LoggerFactory::getInstance() will be called many times during the course of handling a typical MediaWiki request. The interface_exists() guard condition it uses is an attempt to provide an informative error message when Composer managed libraries are not installed. This check is only needed on the first invocation of getInstance() to be effective. Using an additional boolean to guard the interface_exists() call will allow the PHP runtime to avoid a potentially expensive (at least compared to a static boolean comparison) function call. This is the sort of thing that smells of premature optimization, but its addition is in fact informed by examination of performance reports from the Wikimedia production environment. Bug: T115729 Change-Id: I437bcb5326b06145081f2b86f6c4d0c8dc1a318c --- diff --git a/includes/debug/logger/LoggerFactory.php b/includes/debug/logger/LoggerFactory.php index f1b24e76bd..92fbb460ef 100644 --- a/includes/debug/logger/LoggerFactory.php +++ b/includes/debug/logger/LoggerFactory.php @@ -94,18 +94,22 @@ class LoggerFactory { * @return \\Psr\\Log\\LoggerInterface */ public static function getInstance( $channel ) { - if ( !interface_exists( '\Psr\Log\LoggerInterface' ) ) { - $message = ( - 'MediaWiki requires the PSR-3 logging ' . - "library to be present. This library is not embedded directly in MediaWiki's " . - "git repository and must be installed separately by the end user.\n\n" . - 'Please see mediawiki.org for help on installing ' . - 'the required components.' - ); - echo $message; - trigger_error( $message, E_USER_ERROR ); - die( 1 ); + static $hasPSR3Interface = null; + if ( $hasPSR3Interface === null ) { + $hasPSR3Interface = interface_exists( '\Psr\Log\LoggerInterface' ); + if ( !$hasPSR3Interface ) { + $message = ( + 'MediaWiki requires the PSR-3 logging ' . + "library to be present. This library is not embedded directly in MediaWiki's " . + "git repository and must be installed separately by the end user.\n\n" . + 'Please see mediawiki.org for help on installing ' . + 'the required components.' + ); + echo $message; + trigger_error( $message, E_USER_ERROR ); + die( 1 ); + } } return self::getProvider()->getLogger( $channel );