Commit of various live hacks
[lhc/web/wiklou.git] / includes / cache / SquidUpdate.php
index e8e57cd..897397e 100644 (file)
 class SquidUpdate {
        var $urlArr, $mMaxTitles;
 
-       function __construct( $urlArr = Array(), $maxTitles = false ) {
+       /**
+        * @param $urlArr array
+        * @param $maxTitles bool|int
+        */
+       function __construct( $urlArr = array(), $maxTitles = false ) {
                global $wgMaxSquidPurgeTitles;
                if ( $maxTitles === false ) {
                        $this->mMaxTitles = $wgMaxSquidPurgeTitles;
@@ -121,15 +125,12 @@ class SquidUpdate {
        static function purge( $urlArr ) {
                global $wgSquidServers, $wgHTCPMulticastRouting;
 
-               /*if ( (@$wgSquidServers[0]) == 'echo' ) {
-                       echo implode("<br />\n", $urlArr) . "<br />\n";
-                       return;
-               }*/
-
                if( !$urlArr ) {
                        return;
                }
 
+               wfDebug( "Squid purge: " . implode( ' ', $urlArr ) . "\n" );
+
                if ( $wgHTCPMulticastRouting ) {
                        SquidUpdate::HTCPPurge( $urlArr );
                }
@@ -201,10 +202,25 @@ class SquidUpdate {
                                        throw new MWException( "Invalid HTCP rule for URL $url\n" );
                                }
 
+                               // Try and incremement value in APC cache
+                               $id = apc_inc( 'squidhtcppurge' );
+                               if ( $id === false ) {
+                                       // If false, means it didn't work
+                                       // Chances are that means it isn't in the cache
+                                       // Start saving a cached value
+                                       $add = apc_add( 'squidhtcppurge', 1 );
+                                       if ( $add === false ) {
+                                               wfDebugLog( 'htcp', 'Unable to set value to APC cache' );
+                                               $id = 0;
+                                       } else {
+                                               $id = $add;
+                                       }
+                               }
+
                                // Construct a minimal HTCP request diagram
                                // as per RFC 2756
                                // Opcode 'CLR', no response desired, no auth
-                               $htcpTransID = rand();
+                               $htcpTransID = $id;
 
                                $htcpSpecifier = pack( 'na4na*na8n',
                                        4, 'HEAD', strlen( $url ), $url,
@@ -250,7 +266,7 @@ class SquidUpdate {
        static function expand( $url ) {
                return wfExpandUrl( $url, PROTO_INTERNAL );
        }
-       
+
        /**
         * Find the HTCP routing rule to use for a given URL.
         * @param $url string URL to match
@@ -265,5 +281,4 @@ class SquidUpdate {
                }
                return false;
        }
-       
 }