56 if ( !isset( $this->conn ) ) {
57 $status = $this->manager->get( $this->key );
58 if ( !$status->isOK() ) {
62 $this->conn = $status->value[
'conn'];
64 $this->hostName = $status->value[
'hostName'];
68 stream_set_timeout( $this->conn, 0, (
int)( $this->timeout * 1e6 * 1.5 ) );
71 return Status::newGood( $this->conn );
79 $args = str_replace(
' ',
'%20', $args );
80 $cmd = implode(
' ', $args );
81 $status = $this->getConn();
82 if ( !$status->isOK() ) {
85 $conn = $status->value;
86 $this->logger->debug(
"Sending pool counter command: $cmd" );
87 if ( fwrite( $conn,
"$cmd\n" ) ===
false ) {
88 return Status::newFatal(
'poolcounter-write-error', $this->hostName );
90 $response = fgets( $conn );
91 if ( $response ===
false ) {
92 return Status::newFatal(
'poolcounter-read-error', $this->hostName );
94 $response = rtrim( $response,
"\r\n" );
95 $this->logger->debug(
"Got pool counter response: $response" );
96 $parts = explode(
' ', $response, 2 );
97 $responseType = $parts[0];
98 switch ( $responseType ) {
113 $parts = explode(
' ', $parts[1], 2 );
114 $errorMsg = $parts[1] ??
'(no message given)';
115 return Status::newFatal(
'poolcounter-remote-error', $errorMsg, $this->hostName );
117 return Status::newGood( constant(
"PoolCounter::$responseType" ) );