59 public function get( $key ) {
61 foreach ( $this->hostNames as $hostName ) {
62 $hashes[$hostName] = md5( $hostName . $key );
69 foreach ( $hashes as $hostName => $hash ) {
70 if ( isset( $this->conns[$hostName] ) ) {
71 $this->refCounts[$hostName]++;
72 return Status::newGood(
73 [
'conn' => $this->conns[$hostName],
'hostName' => $hostName ] );
75 $parts = IPUtils::splitHostAndPort( $hostName );
76 if ( $parts ===
false ) {
77 $errstr =
'\'servers\
' config incorrectly configured.';
78 return Status::newFatal(
'poolcounter-connection-error', $errstr, $hostName );
81 $this->host = IPUtils::isValidIPv6( $parts[0] ) ?
'[' . $parts[0] .
']' : $parts[0];
82 $this->port = $parts[1] ?: 7531;
84 $conn = @$this->open( $this->host, $this->port, $errno, $errstr );
90 return Status::newFatal(
'poolcounter-connection-error', $errstr, $hostName );
93 wfDebug(
"Connected to pool counter server: $hostName\n" );
94 $this->conns[$hostName] = $conn;
95 $this->refCounts[$hostName] = 1;
96 return Status::newGood( [
'conn' => $conn,
'hostName' => $hostName ] );
136 foreach ( $this->conns as $hostName => $otherConn ) {
137 if ( $conn === $otherConn ) {
138 if ( $this->refCounts[$hostName] ) {
139 $this->refCounts[$hostName]--;
141 if ( !$this->refCounts[$hostName] ) {
143 unset( $this->conns[$hostName] );