use Wikimedia\Rdbms\ChronologyProtector;
use Wikimedia\Rdbms\LBFactory;
use Wikimedia\Rdbms\DBConnectionError;
+use Liuggio\StatsdClient\Sender\SocketSender;
/**
* The MediaWiki class is the helper class for the index.php entry point.
if ( function_exists( 'register_postsend_function' ) ) {
// https://github.com/facebook/hhvm/issues/1230
register_postsend_function( $callback );
+ /** @noinspection PhpUnusedLocalVariableInspection */
$blocksHttpClient = false;
} else {
if ( function_exists( 'fastcgi_finish_request' ) ) {
fastcgi_finish_request();
+ /** @noinspection PhpUnusedLocalVariableInspection */
$blocksHttpClient = false;
} else {
// Either all DB and deferred updates should happen or none.
wfDebug( "Request ended normally\n" );
}
+ /**
+ * Send out any buffered statsd data according to sampling rules
+ *
+ * @param IBufferingStatsdDataFactory $stats
+ * @param Config $config
+ * @throws ConfigException
+ * @since 1.31
+ */
+ public static function emitBufferedStatsdData(
+ IBufferingStatsdDataFactory $stats, Config $config
+ ) {
+ if ( $config->get( 'StatsdServer' ) && $stats->hasData() ) {
+ try {
+ $statsdServer = explode( ':', $config->get( 'StatsdServer' ) );
+ $statsdHost = $statsdServer[0];
+ $statsdPort = isset( $statsdServer[1] ) ? $statsdServer[1] : 8125;
+ $statsdSender = new SocketSender( $statsdHost, $statsdPort );
+ $statsdClient = new SamplingStatsdClient( $statsdSender, true, false );
+ $statsdClient->setSamplingRates( $config->get( 'StatsdSamplingRates' ) );
+ $statsdClient->send( $stats->getData() );
+
+ $stats->clearData(); // empty buffer for the next round
+ } catch ( Exception $ex ) {
+ MWExceptionHandler::logException( $ex );
+ }
+ }
+ }
+
/**
* Potentially open a socket and sent an HTTP request back to the server
* to run a specified number of jobs. This registers a callback to cleanup