54 $status = $this->manager->get( $this->key );
55 if ( !$status->isOK() ) {
59 $this->conn = $status->value[
'conn'];
61 $this->hostName = $status->value[
'hostName'];
65 stream_set_timeout( $this->conn, 0, (
int)( $this->timeout * 1e6 * 1.5 ) );
68 return Status::newGood( $this->conn );
76 $args = str_replace(
' ',
'%20', $args );
77 $cmd = implode(
' ', $args );
78 $status = $this->getConn();
79 if ( !$status->isOK() ) {
82 $conn = $status->value;
83 $this->logger->debug(
"Sending pool counter command: $cmd" );
84 if ( fwrite( $conn,
"$cmd\n" ) ===
false ) {
85 return Status::newFatal(
'poolcounter-write-error', $this->hostName );
87 $response = fgets( $conn );
88 if ( $response ===
false ) {
89 return Status::newFatal(
'poolcounter-read-error', $this->hostName );
91 $response = rtrim( $response,
"\r\n" );
92 $this->logger->debug(
"Got pool counter response: $response" );
93 $parts = explode(
' ', $response, 2 );
94 $responseType = $parts[0];
95 switch ( $responseType ) {
110 $parts = explode(
' ', $parts[1], 2 );
111 $errorMsg = $parts[1] ??
'(no message given)';
112 return Status::newFatal(
'poolcounter-remote-error', $errorMsg, $this->hostName );
114 return Status::newGood( constant(
"PoolCounter::$responseType" ) );