73 public function get( $key ) {
75 foreach ( $this->hostNames as $hostName ) {
76 $hashes[$hostName] = md5( $hostName . $key );
83 foreach ( $hashes as $hostName => $hash ) {
84 if ( isset( $this->conns[$hostName] ) ) {
85 $this->refCounts[$hostName]++;
86 return Status::newGood(
87 [
'conn' => $this->conns[$hostName],
'hostName' => $hostName ] );
89 $parts = IPUtils::splitHostAndPort( $hostName );
90 if ( $parts ===
false ) {
91 $errstr =
'\'servers\
' config incorrectly configured.';
92 return Status::newFatal(
'poolcounter-connection-error', $errstr, $hostName );
95 $this->host = IPUtils::isValidIPv6( $parts[0] ) ?
'[' . $parts[0] .
']' : $parts[0];
96 $this->port = $parts[1] ?: 7531;
98 $conn = @$this->open( $this->host, $this->port, $errno, $errstr );
104 return Status::newFatal(
'poolcounter-connection-error', $errstr, $hostName );
107 wfDebug(
"Connected to pool counter server: $hostName\n" );
108 $this->conns[$hostName] = $conn;
109 $this->refCounts[$hostName] = 1;
110 return Status::newGood( [
'conn' => $conn,
'hostName' => $hostName ] );
150 foreach ( $this->conns as $hostName => $otherConn ) {
151 if ( $conn === $otherConn ) {
152 if ( $this->refCounts[$hostName] ) {
153 $this->refCounts[$hostName]--;
155 if ( !$this->refCounts[$hostName] ) {
157 unset( $this->conns[$hostName] );