From 61cd5b2313a74860c088bcad3d2097b2548af66a Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 29 Jan 2008 00:49:06 +0000 Subject: [PATCH] Replacing a live hack in wfIncrStats: 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 | 8 ++++++++ includes/GlobalFunctions.php | 30 +++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 4959770845..0aef5327a6 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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). */ diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 56408a0f1b..7237d74584 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -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 -- 2.20.1