50 $this->manager = $manager;
57 if ( !isset( $this->conn ) ) {
58 $status = $this->manager->get( $this->key );
59 if ( !$status->isOK() ) {
63 $this->conn = $status->value[
'conn'];
65 $this->hostName = $status->value[
'hostName'];
69 stream_set_timeout( $this->conn, 0, (
int)( $this->timeout * 1e6 * 1.5 ) );
80 $args = str_replace(
' ',
'%20', $args );
81 $cmd = implode(
' ', $args );
82 $status = $this->getConn();
83 if ( !$status->isOK() ) {
86 $conn = $status->value;
87 wfDebug(
"Sending pool counter command: $cmd\n" );
88 if ( fwrite( $conn,
"$cmd\n" ) ===
false ) {
91 $response = fgets( $conn );
92 if ( $response ===
false ) {
95 $response = rtrim( $response,
"\r\n" );
96 wfDebug(
"Got pool counter response: $response\n" );
97 $parts = explode(
' ', $response, 2 );
98 $responseType = $parts[0];
99 switch ( $responseType ) {
114 $parts = explode(
' ', $parts[1], 2 );
115 $errorMsg = $parts[1] ??
'(no message given)';
116 return Status::newFatal(
'poolcounter-remote-error', $errorMsg, $this->hostName );
126 $status = $this->precheckAcquire();
127 if ( !$status->isGood() ) {
130 return $this->sendCommand(
'ACQ4ME', $this->key, $this->workers, $this->maxqueue,
131 $timeout ?? $this->timeout );
139 $status = $this->precheckAcquire();
140 if ( !$status->isGood() ) {
143 return $this->sendCommand(
'ACQ4ANY', $this->key, $this->workers, $this->maxqueue,
144 $timeout ?? $this->timeout );
151 $status = $this->sendCommand(
'RELEASE' );
154 $this->manager->close( $this->conn );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Semaphore semantics to restrict how many workers may concurrently perform a task.
static newFatal( $message,... $parameters)
Factory function for fatal errors.
static newGood( $value=null)
Factory function for good results.