コード例 #1
0
ファイル: generateVisits.php プロジェクト: ntulip/piwik
if (Piwik_PluginsManager::getInstance()->isPluginActivated('Provider')) {
    Piwik_PluginsManager::getInstance()->unloadPlugin('Provider');
}
// we set the DO NOT load plugins so that the Tracker generator doesn't load the plugins we've just disabled.
// if for some reasons you want to load the plugins, comment this line, and disable the plugin Provider in the plugins interface
Piwik_PluginsManager::getInstance()->doNotLoadPlugins();
$generator = new Piwik_Tracker_Generator();
$generator->setMaximumUrlDepth(3);
//$generator->disableProfiler();
$generator->setIdSite($idSite);
$nbActionsTotal = 0;
//$generator->emptyAllLogTables();
$generator->init();
$t = new Piwik_Timer();
$startTime = time() - ($daysToCompute - 1) * 86400;
while ($startTime <= time()) {
    $visitors = rand($minVisitors, $maxVisitors);
    $actions = $nbActions;
    $generator->setTimestampToUse($startTime);
    $nbActionsTotalThisDay = $generator->generate($visitors, $actions);
    $actionsPerVisit = round($nbActionsTotalThisDay / $visitors);
    print "Generated {$visitors} unique visitors and {$actionsPerVisit} actions per visit for the " . date("Y-m-d", $startTime) . "<br>\n";
    $startTime += 86400;
    $nbActionsTotal += $nbActionsTotalThisDay;
    sleep(1);
}
echo "<br>Total actions: {$nbActionsTotal}";
echo "<br>Total requests per sec: " . round($nbActionsTotal / $t->getTime(), 0);
echo "<br>" . $t;
$generator->end();
ob_end_flush();