Replacing a live hack in wfIncrStats:
authorBrion Vibber <brion@users.mediawiki.org>
Tue, 29 Jan 2008 00:49:06 +0000 (00:49 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Tue, 29 Jan 2008 00:49:06 +0000 (00:49 +0000)
Add $wgStatsMethod to control how (and whether) to update the stats.
Setting to 'cache' (the default) gives the previous behavior of updating in $wgMemc.
Setting to 'udp' sends a line to the UDP profiling host.
Setting to false or 'disabled' or whatever will disable it.

includes/DefaultSettings.php
includes/GlobalFunctions.php

index 4959770..0aef532 100644 (file)
@@ -1551,6 +1551,14 @@ $wgDebugFunctionEntry = 0;
 /** Lots of debugging output from SquidUpdate.php */
 $wgDebugSquid = false;
 
+/*
+ * Destination for wfIncrStats() data...
+ * 'cache' to go into the system cache, if enabled (memcached)
+ * 'udp' to be sent to the UDP profiler (see $wgUDPProfilerHost)
+ * false to disable
+ */
+$wgStatsMethod = 'cache';
+
 /** Whereas to count the number of time an article is viewed.
  * Does not work if pages are cached (for example with squid).
  */
index 56408a0..7237d74 100644 (file)
@@ -1644,13 +1644,29 @@ function wfMkdirParents( $fullDir, $mode = 0777 ) {
 /**
  * Increment a statistics counter
  */
- function wfIncrStats( $key ) {
-        global $wgMemc;
-        $key = wfMemcKey( 'stats', $key );
-        if ( is_null( $wgMemc->incr( $key ) ) ) {
-                $wgMemc->add( $key, 1 );
-        }
- }
+function wfIncrStats( $key ) {
+       global $wgStatsMethod;
+       
+       if( $wgStatsMethod == 'udp' ) {
+               global $wgUDPProfilerHost, $wgUDPProfilerPort, $wgDBname;
+               static $socket;
+               if (!$socket) {
+                       $socket=socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
+                       $statline="stats/{$wgDBname} - 1 1 1 1 1 -total\n";
+                       socket_sendto($socket,$statline,strlen($statline),0,$wgUDPProfilerHost,$wgUDPProfilerPort);
+               }
+               $statline="stats/{$wgDBname} - 1 1 1 1 1 {$key}\n";
+               @socket_sendto($socket,$statline,strlen($statline),0,$wgUDPProfilerHost,$wgUDPProfilerPort);
+       } elseif( $wgStatsMethod == 'cache' ) {
+               global $wgMemc;
+               $key = wfMemcKey( 'stats', $key );
+               if ( is_null( $wgMemc->incr( $key ) ) ) {
+                       $wgMemc->add( $key, 1 );
+               }
+       } else {
+               // Disabled
+       }
+}
 
 /**
  * @param mixed $nr The number to format