X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FSquidPurgeClient.php;h=7d75f2ca9ae15d3284a033a1c8617f87b722dafd;hb=b23188b8adc15c477b1cecc138af2f35c95d82e8;hp=7cd2b033b0c133c84f352cb2da40d3f29edc6fb5;hpb=2705e07bfd080de448116dc9d6c0d109e29fa01e;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/SquidPurgeClient.php b/includes/SquidPurgeClient.php index 7cd2b033b0..7d75f2ca9a 100644 --- a/includes/SquidPurgeClient.php +++ b/includes/SquidPurgeClient.php @@ -21,9 +21,9 @@ */ /** - * An HTTP 1.0 client built for the purposes of purging Squid and Varnish. - * Uses asynchronous I/O, allowing purges to be done in a highly parallel - * manner. + * An HTTP 1.0 client built for the purposes of purging Squid and Varnish. + * Uses asynchronous I/O, allowing purges to be done in a highly parallel + * manner. * * Could be replaced by curl_multi_exec() or some such. */ @@ -44,7 +44,15 @@ class SquidPurgeClient { * The socket resource, or null for unconnected, or false for disabled due to error */ var $socket; - + + var $readBuffer; + + var $bodyRemaining; + + /** + * @param $server string + * @param $options array + */ public function __construct( $server, $options = array() ) { $parts = explode( ':', $server, 2 ); $this->host = $parts[0]; @@ -115,7 +123,7 @@ class SquidPurgeClient { return array( $socket ); } - /** + /** * Get the host's IP address. * Does not support IPv6 at present due to the lack of a convenient interface in PHP. */ @@ -168,11 +176,32 @@ class SquidPurgeClient { * @param $url string */ public function queuePurge( $url ) { + global $wgSquidPurgeUseHostHeader; $url = SquidUpdate::expand( str_replace( "\n", '', $url ) ); - $this->requests[] = "PURGE $url HTTP/1.0\r\n" . - "Connection: Keep-Alive\r\n" . - "Proxy-Connection: Keep-Alive\r\n" . - "User-Agent: " . Http::userAgent() . ' ' . __CLASS__ . "\r\n\r\n"; + $request = array(); + if ( $wgSquidPurgeUseHostHeader ) { + $url = wfParseUrl( $url ); + $host = $url['host']; + if ( isset( $url['port'] ) && strlen( $url['port'] ) > 0 ) { + $host .= ":" . $url['port']; + } + $path = $url['path']; + if ( isset( $url['query'] ) && is_string( $url['query'] ) ) { + $path = wfAppendQuery( $path, $url['query'] ); + } + $request[] = "PURGE $path HTTP/1.1"; + $request[] = "Host: $host"; + } else { + $request[] = "PURGE $url HTTP/1.0"; + } + $request[] = "Connection: Keep-Alive"; + $request[] = "Proxy-Connection: Keep-Alive"; + $request[] = "User-Agent: " . Http::userAgent() . ' ' . __CLASS__; + // Two ''s to create \r\n\r\n + $request[] = ''; + $request[] = ''; + + $this->requests[] = implode( "\r\n", $request ); if ( $this->currentRequestIndex === null ) { $this->nextRequest(); } @@ -340,6 +369,9 @@ class SquidPurgeClient { $this->bodyRemaining = null; } + /** + * @param $msg string + */ protected function log( $msg ) { wfDebugLog( 'squid', __CLASS__." ($this->host): $msg\n" ); } @@ -353,6 +385,9 @@ class SquidPurgeClientPool { var $clients = array(); var $timeout = 5; + /** + * @param $options array + */ function __construct( $options = array() ) { if ( isset( $options['timeout'] ) ) { $this->timeout = $options['timeout']; @@ -372,6 +407,9 @@ class SquidPurgeClientPool { $startTime = microtime( true ); while ( !$done ) { $readSockets = $writeSockets = array(); + /** + * @var $client SquidPurgeClient + */ foreach ( $this->clients as $clientIndex => $client ) { $sockets = $client->getReadSocketsForSelect(); foreach ( $sockets as $i => $socket ) { @@ -391,7 +429,7 @@ class SquidPurgeClientPool { $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; }