71 public function get( $key ) {
73 foreach ( $this->hostNames as $hostName ) {
74 $hashes[$hostName] = md5( $hostName . $key );
81 foreach ( $hashes as $hostName => $hash ) {
82 if ( isset( $this->conns[$hostName] ) ) {
83 $this->refCounts[$hostName]++;
84 return Status::newGood(
85 [
'conn' => $this->conns[$hostName],
'hostName' => $hostName ] );
87 $parts = IPUtils::splitHostAndPort( $hostName );
88 if ( $parts ===
false ) {
89 $errstr =
'\'servers\
' config incorrectly configured.';
90 return Status::newFatal(
'poolcounter-connection-error', $errstr, $hostName );
93 $this->host = IPUtils::isValidIPv6( $parts[0] ) ?
'[' . $parts[0] .
']' : $parts[0];
94 $this->port = $parts[1] ?: 7531;
96 $conn = @$this->open( $this->host, $this->port, $errno, $errstr );
102 return Status::newFatal(
'poolcounter-connection-error', $errstr, $hostName );
105 wfDebug(
"Connected to pool counter server: $hostName\n" );
106 $this->conns[$hostName] = $conn;
107 $this->refCounts[$hostName] = 1;
108 return Status::newGood( [
'conn' => $conn,
'hostName' => $hostName ] );
148 foreach ( $this->conns as $hostName => $otherConn ) {
149 if ( $conn === $otherConn ) {
150 if ( $this->refCounts[$hostName] ) {
151 $this->refCounts[$hostName]--;
153 if ( !$this->refCounts[$hostName] ) {
155 unset( $this->conns[$hostName] );