* Could be replaced by curl_multi_exec() or some such.
*/
class SquidPurgeClient {
- var $host, $port, $ip;
+ /** @var string */
+ protected $host;
- var $readState = 'idle';
- var $writeBuffer = '';
- var $requests = array();
- var $currentRequestIndex;
+ /** @var int */
+ protected $port;
+
+ /** @var string|bool */
+ protected $ip;
+
+ /** @var string */
+ protected $readState = 'idle';
+
+ /** @var string */
+ protected $writeBuffer = '';
+
+ /** @var array */
+ protected $requests = array();
+
+ /** @var mixed */
+ protected $currentRequestIndex;
const EINTR = 4;
const EAGAIN = 11;
const BUFFER_SIZE = 8192;
/**
- * The socket resource, or null for unconnected, or false for disabled due to error
+ * @var resource|null The socket resource, or null for unconnected, or false
+ * for disabled due to error.
*/
- var $socket;
+ protected $socket;
- var $readBuffer;
+ /** @var string */
+ protected $readBuffer;
- var $bodyRemaining;
+ /** @var int */
+ protected $bodyRemaining;
/**
- * @param $server string
- * @param $options array
+ * @param string $server
+ * @param array $options
*/
public function __construct( $server, $options = array() ) {
$parts = explode( ':', $server, 2 );
/**
* Get the host's IP address.
* Does not support IPv6 at present due to the lack of a convenient interface in PHP.
+ * @throws MWException
+ * @return string
*/
protected function getIP() {
if ( $this->ip === null ) {
/**
* Queue a purge operation
*
- * @param $url string
+ * @param string $url
*/
public function queuePurge( $url ) {
- global $wgPurgeHttp11;
+ global $wgSquidPurgeUseHostHeader;
$url = SquidUpdate::expand( str_replace( "\n", '', $url ) );
$request = array();
- if ( $wgPurgeHttp11 ) {
+ if ( $wgSquidPurgeUseHostHeader ) {
$url = wfParseUrl( $url );
$host = $url['host'];
if ( isset( $url['port'] ) && strlen( $url['port'] ) > 0 ) {
if ( count( $lines ) < 2 ) {
return 'done';
}
- if ( $this->readState == 'status' ) {
+ if ( $this->readState == 'status' ) {
$this->processStatusLine( $lines[0] );
} else { // header
$this->processHeaderLine( $lines[0] );
return 'done';
}
default:
- throw new MWException( __METHOD__.': unexpected state' );
+ throw new MWException( __METHOD__ . ': unexpected state' );
}
}
/**
- * @param $line
+ * @param string $line
* @return
*/
protected function processStatusLine( $line ) {
}
/**
- * @param $line string
+ * @param string $line
*/
protected function processHeaderLine( $line ) {
if ( preg_match( '/^Content-Length: (\d+)$/i', $line, $m ) ) {
}
/**
- * @param $msg string
+ * @param string $msg
*/
protected function log( $msg ) {
- wfDebugLog( 'squid', __CLASS__." ($this->host): $msg\n" );
+ wfDebugLog( 'squid', __CLASS__ . " ($this->host): $msg" );
}
}
class SquidPurgeClientPool {
+ /** @var array of SquidPurgeClient */
+ protected $clients = array();
- /**
- * @var array of SquidPurgeClient
- */
- var $clients = array();
- var $timeout = 5;
+ /** @var int */
+ protected $timeout = 5;
/**
- * @param $options array
+ * @param array $options
*/
function __construct( $options = array() ) {
if ( isset( $options['timeout'] ) ) {
}
/**
- * @param $client SquidPurgeClient
+ * @param SquidPurgeClient $client
* @return void
*/
public function addClient( $client ) {
$numReady = socket_select( $readSockets, $writeSockets, $exceptSockets, $timeout );
wfRestoreWarnings();
if ( $numReady === false ) {
- wfDebugLog( 'squid', __METHOD__.': Error in stream_select: ' .
+ wfDebugLog( 'squid', __METHOD__ . ': Error in stream_select: ' .
socket_strerror( socket_last_error() ) . "\n" );
break;
}
// Check for timeout, use 1% tolerance since we aimed at having socket_select()
// exit at precisely the overall timeout
if ( microtime( true ) - $startTime > $this->timeout * 0.99 ) {
- wfDebugLog( 'squid', __CLASS__.": timeout ({$this->timeout}s)\n" );
+ wfDebugLog( 'squid', __CLASS__ . ": timeout ({$this->timeout}s)\n" );
break;
} elseif ( !$numReady ) {
continue;