diff options
author | benakamoorthi <benaka.moorthi@gmail.com> | 2012-07-22 20:00:17 +0400 |
---|---|---|
committer | benakamoorthi <benaka.moorthi@gmail.com> | 2012-07-22 20:00:17 +0400 |
commit | 20f14b0babd0678e083d44f85d2fcb857c61789c (patch) | |
tree | 62b622567b05a26ce238575a57f3f61dc857f34c /tests/LocalTracker.php | |
parent | e9dc68898a03361d406c6f0c8a20d7c828cf6000 (diff) |
Refs #3177, added benchmarking system and set of benchmarks to test Piwik performance.
Notes:
* Added LocalTracker tracker that can be used w/ tests & benchmarks to speed things up.
* Modified HTTP header sending code to use intermediate utility function.
git-svn-id: http://dev.piwik.org/svn/trunk@6533 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'tests/LocalTracker.php')
-rwxr-xr-x | tests/LocalTracker.php | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/tests/LocalTracker.php b/tests/LocalTracker.php new file mode 100755 index 0000000000..04117a8c65 --- /dev/null +++ b/tests/LocalTracker.php @@ -0,0 +1,128 @@ +<?php + +$GLOBALS['PIWIK_TRACKER_DEBUG'] = false; +$GLOBALS['PIWIK_TRACKER_DEBUG_FORCE_SCHEDULED_TASKS'] = false; +if (!defined('PIWIK_ENABLE_TRACKING')) +{ + define('PIWIK_ENABLE_TRACKING', true); +} + +require_once PIWIK_INCLUDE_PATH.'/core/Tracker.php'; +require_once PIWIK_INCLUDE_PATH.'/core/Tracker/Db.php'; +require_once PIWIK_INCLUDE_PATH.'/core/Tracker/IgnoreCookie.php'; +require_once PIWIK_INCLUDE_PATH.'/core/Tracker/Visit.php'; +require_once PIWIK_INCLUDE_PATH.'/core/Tracker/GoalManager.php'; +require_once PIWIK_INCLUDE_PATH.'/core/Tracker/Action.php'; +require_once PIWIK_INCLUDE_PATH.'/libs/PiwikTracker/PiwikTracker.php'; + +/** + * Tracker that uses core/Tracker.php directly. + */ +class Piwik_LocalTracker extends PiwikTracker +{ + protected function sendRequest( $url, $method = 'GET', $data = null, $force = false ) + { + // if doing a bulk request, store the url + if ($this->doBulkRequests && !$force) + { + $this->storedTrackingActions[] = $url; + return true; + } + + if ($method == 'POST') + { + $requests = array(); + foreach ($this->storedTrackingActions as $action) + { + $requests[] = $this->parseUrl($action); + } + + $testEnvironmentArgs = array(); + } + else + { + $testEnvironmentArgs = $this->parseUrl($url); + $requests = array($testEnvironmentArgs); + } + + // unset cached values + Piwik_Common::$trackerCache = null; + Piwik_Tracker::setForceIp(null); + Piwik_Tracker::setForceDateTime(null); + Piwik_Tracker::setForceVisitorId(null); + + // save some values + $plugins = Piwik_Config::getInstance()->Plugins['Plugins']; + $pluginsTracker = Piwik_Config::getInstance()->Plugins_Tracker['Plugins_Tracker']; + $oldTrackerConfig = Piwik_Config::getInstance()->Tracker; + Piwik_PluginsManager::getInstance()->unloadPlugins(); + + // modify config + $GLOBALS['PIWIK_TRACKER_MODE'] = true; + $GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING'] = true; + Piwik_Common::$initTrackerMode = false; + Piwik_Tracker::setTestEnvironment($testEnvironmentArgs, $method); + + // set language + $oldLang = $_SERVER['HTTP_ACCEPT_LANGUAGE']; + $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $this->acceptLanguage; + + // set user agent + $oldUserAgent = $_SERVER['HTTP_USER_AGENT']; + $_SERVER['HTTP_USER_AGENT'] = $this->userAgent; + + // set cookie + $oldCookie = $_COOKIE; + parse_str(parse_url($this->requestCookie, PHP_URL_QUERY), $_COOKIE); + + // do tracking and capture output + ob_start(); + + $localTracker = new Piwik_Tracker($requests); + try { + $localTracker->main(); + } catch(Exception $e) { + echo "Error:" . $e->getMessage(); + } + + $output = ob_get_contents(); + + ob_end_clean(); + + // restore vars + Piwik_Config::getInstance()->Plugins_Tracker['Plugins_Tracker'] = $pluginsTracker; + Piwik_Config::getInstance()->Tracker = $oldTrackerConfig; + $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $oldLang; + $_SERVER['HTTP_USER_AGENT'] = $oldUserAgent; + $_COOKIE = $oldCookie; + $GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING'] = false; + $GLOBALS['PIWIK_TRACKER_MODE'] = false; + unset($_GET['bots']); + + // reload plugins + Piwik_PluginsManager::getInstance()->loadPlugins($plugins); + + return $output; + } + + private function parseUrl( $url ) + { + // parse url + $query = parse_url($url, PHP_URL_QUERY); + if ($query === false) + { + continue; + } + + parse_str($query, $args); + + // make sure bots is set if needed + if (isset($args['bots'])) + { + $_GET['bots'] = true; + } + + return $args; + } +} + |