49 $this->hostNames = $conf[
'servers'];
50 $this->timeout = $conf[
'timeout'] ?? 0.1;
51 $this->connect_timeout = $conf[
'connect_timeout'] ?? 0;
52 if ( !count( $this->hostNames ) ) {
53 throw new MWException( __METHOD__ .
': no servers configured' );
61 public function get( $key ) {
63 foreach ( $this->hostNames as $hostName ) {
64 $hashes[$hostName] = md5( $hostName . $key );
71 foreach ( $hashes as $hostName => $hash ) {
72 if ( isset( $this->conns[$hostName] ) ) {
73 $this->refCounts[$hostName]++;
75 [
'conn' => $this->conns[$hostName],
'hostName' => $hostName ] );
77 $parts = explode(
':', $hostName, 2 );
78 if ( count( $parts ) < 2 ) {
82 $conn = @$this->open( $parts[0], $parts[1], $errno, $errstr );
88 return Status::newFatal(
'poolcounter-connection-error', $errstr, $hostName );
91 wfDebug(
"Connected to pool counter server: $hostName\n" );
92 $this->conns[$hostName] = $conn;
93 $this->refCounts[$hostName] = 1;
105 private function open( $host, $port, &$errno, &$errstr ) {
110 if ( $this->connect_timeout > 0 ) {
120 $fp = fsockopen( $host, $port, $errno, $errstr,
$timeout );
121 if ( $fp !==
false || --$tries < 1 ) {
134 foreach ( $this->conns as $hostName => $otherConn ) {
135 if ( $conn === $otherConn ) {
136 if ( $this->refCounts[$hostName] ) {
137 $this->refCounts[$hostName]--;
139 if ( !$this->refCounts[$hostName] ) {
141 unset( $this->conns[$hostName] );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
static newFatal( $message,... $parameters)
Factory function for fatal errors.
static newGood( $value=null)
Factory function for good results.