MediaWiki REL1_32
LoadBalancerSingle.php
Go to the documentation of this file.
1<?php
24namespace Wikimedia\Rdbms;
25
26use InvalidArgumentException;
27
33 private $db;
34
39 public function __construct( array $params ) {
40 if ( !isset( $params['connection'] ) ) {
41 throw new InvalidArgumentException( "Missing 'connection' argument." );
42 }
43
44 $this->db = $params['connection'];
45
46 parent::__construct( [
47 'servers' => [
48 [
49 'type' => $this->db->getType(),
50 'host' => $this->db->getServer(),
51 'dbname' => $this->db->getDBname(),
52 'load' => 1,
53 ]
54 ],
55 'trxProfiler' => $params['trxProfiler'] ?? null,
56 'srvCache' => $params['srvCache'] ?? null,
57 'wanCache' => $params['wanCache'] ?? null,
58 'localDomain' => $params['localDomain'] ?? $this->db->getDomainID()
59 ] );
60
61 if ( isset( $params['readOnlyReason'] ) ) {
62 $this->db->setLBInfo( 'readOnlyReason', $params['readOnlyReason'] );
63 }
64 }
65
72 public static function newFromConnection( IDatabase $db, array $params = [] ) {
73 return new static( array_merge(
74 [ 'localDomain' => $db->getDomainID() ],
75 $params,
76 [ 'connection' => $db ]
77 ) );
78 }
79
80 protected function reallyOpenConnection( array $server, DatabaseDomain $domain ) {
81 return $this->db;
82 }
83}
84
88class_alias( LoadBalancerSingle::class, 'LoadBalancerSingle' );
Class to handle database/prefix specification for IDatabase domains.
Trivial LoadBalancer that always returns an injected connection handle.
static newFromConnection(IDatabase $db, array $params=[])
reallyOpenConnection(array $server, DatabaseDomain $domain)
Open a new network connection to a server (uncached)
Database connection, tracking, load balancing, and transaction manager for a cluster.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
getDomainID()
Return the currently selected domain ID.
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
$params