use WANObjectCache;
use Exception;
use RuntimeException;
+use LogicException;
/**
* An interface for generating database load balancers
protected $perfLogger;
/** @var callable Error logger */
protected $errorLogger;
+ /** @var callable Deprecation logger */
+ protected $deprecationLogger;
/** @var BagOStuff */
protected $srvCache;
/** @var BagOStuff */
$this->errorLogger = isset( $conf['errorLogger'] )
? $conf['errorLogger']
: function ( Exception $e ) {
- trigger_error( E_USER_WARNING, get_class( $e ) . ': ' . $e->getMessage() );
+ trigger_error( get_class( $e ) . ': ' . $e->getMessage(), E_USER_WARNING );
+ };
+ $this->deprecationLogger = isset( $conf['deprecationLogger'] )
+ ? $conf['deprecationLogger']
+ : function ( $msg ) {
+ trigger_error( $msg, E_USER_DEPRECATED );
};
$this->profiler = isset( $conf['profiler'] ) ? $conf['profiler'] : null;
'ChronologyPositionIndex' => isset( $_GET['cpPosIndex'] ) ? $_GET['cpPosIndex'] : null
];
- $this->cliMode = isset( $conf['cliMode'] ) ? $conf['cliMode'] : PHP_SAPI === 'cli';
+ $this->cliMode = isset( $conf['cliMode'] )
+ ? $conf['cliMode']
+ : ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' );
$this->hostname = isset( $conf['hostname'] ) ? $conf['hostname'] : gethostname();
$this->agent = isset( $conf['agent'] ) ? $conf['agent'] : '';
$opts += [
'domain' => false,
'cluster' => false,
- 'timeout' => 60,
+ 'timeout' => $this->cliMode ? 60 : 10,
'ifWritesSince' => null
];
'connLogger' => $this->connLogger,
'replLogger' => $this->replLogger,
'errorLogger' => $this->errorLogger,
+ 'deprecationLogger' => $this->deprecationLogger,
'hostname' => $this->hostname,
'cliMode' => $this->cliMode,
'agent' => $this->agent,
- 'chronologyProtector' => $this->getChronologyProtector()
+ 'chronologyCallback' => function ( ILoadBalancer $lb ) {
+ // Defer ChronologyProtector construction in case setRequestInfo() ends up
+ // being called later (but before the first connection attempt) (T192611)
+ $this->getChronologyProtector()->initLB( $lb );
+ }
];
}
}
public function setRequestInfo( array $info ) {
+ if ( $this->chronProt ) {
+ throw new LogicException( 'ChronologyProtector already initialized.' );
+ }
+
$this->requestInfo = $info + $this->requestInfo;
}