本文整理匯總了PHP中Piwik\Tracker::initCorePiwikInTrackerMode方法的典型用法代碼示例。如果您正苦於以下問題:PHP Tracker::initCorePiwikInTrackerMode方法的具體用法?PHP Tracker::initCorePiwikInTrackerMode怎麽用?PHP Tracker::initCorePiwikInTrackerMode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Piwik\Tracker
的用法示例。
在下文中一共展示了Tracker::initCorePiwikInTrackerMode方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: runScheduledTasks
/**
* Tracker requests will automatically trigger the Scheduled tasks.
* This is useful for users who don't setup the cron,
* but still want daily/weekly/monthly PDF reports emailed automatically.
*
* This is similar to calling the API CoreAdminHome.runScheduledTasks
*/
public function runScheduledTasks()
{
$now = time();
// Currently, there are no hourly tasks. When there are some,
// this could be too aggressive minimum interval (some hours would be skipped in case of low traffic)
$minimumInterval = TrackerConfig::getConfigValue('scheduled_tasks_min_interval');
// If the user disabled browser archiving, he has already setup a cron
// To avoid parallel requests triggering the Scheduled Tasks,
// Get last time tasks started executing
$cache = Cache::getCacheGeneral();
if ($minimumInterval <= 0 || empty($cache['isBrowserTriggerEnabled'])) {
Common::printDebug("-> Scheduled tasks not running in Tracker: Browser archiving is disabled.");
return;
}
$nextRunTime = $cache['lastTrackerCronRun'] + $minimumInterval;
if (defined('DEBUG_FORCE_SCHEDULED_TASKS') && DEBUG_FORCE_SCHEDULED_TASKS || $cache['lastTrackerCronRun'] === false || $nextRunTime < $now) {
$cache['lastTrackerCronRun'] = $now;
Cache::setCacheGeneral($cache);
Tracker::initCorePiwikInTrackerMode();
Option::set('lastTrackerCronRun', $cache['lastTrackerCronRun']);
Common::printDebug('-> Scheduled Tasks: Starting...');
// save current user privilege and temporarily assume Super User privilege
$isSuperUser = Piwik::hasUserSuperUserAccess();
// Scheduled tasks assume Super User is running
Piwik::setUserHasSuperUserAccess();
$tokens = CronArchive::getSuperUserTokenAuths();
$tokenAuth = reset($tokens);
$invokeScheduledTasksUrl = SettingsPiwik::getPiwikUrl() . "?module=API&format=csv&convertToUnicode=0&method=CoreAdminHome.runScheduledTasks&trigger=archivephp&token_auth={$tokenAuth}";
$cliMulti = new CliMulti();
$responses = $cliMulti->request(array($invokeScheduledTasksUrl));
$resultTasks = reset($responses);
// restore original user privilege
Piwik::setUserHasSuperUserAccess($isSuperUser);
Common::printDebug($resultTasks);
Common::printDebug('Finished Scheduled Tasks.');
} else {
Common::printDebug("-> Scheduled tasks not triggered.");
}
Common::printDebug("Next run will be from: " . date('Y-m-d H:i:s', $nextRunTime) . ' UTC');
}
示例2: getCacheGeneral
/**
* Returns contents of general (global) cache.
* If the cache file tmp/cache/tracker/general.php does not exist yet, create it
*
* @return array
*/
public static function getCacheGeneral()
{
$cache = self::getCache();
$cacheContent = $cache->fetch(self::$cacheIdGeneral);
if (false !== $cacheContent) {
return $cacheContent;
}
Tracker::initCorePiwikInTrackerMode();
$cacheContent = array('isBrowserTriggerEnabled' => Rules::isBrowserTriggerEnabled(), 'lastTrackerCronRun' => Option::get('lastTrackerCronRun'));
/**
* Triggered before the [general tracker cache](/guides/all-about-tracking#the-tracker-cache)
* is saved to disk. This event can be used to add extra content to the cache.
*
* Data that is used during tracking but is expensive to compute/query should be
* cached to keep tracking efficient. One example of such data are options
* that are stored in the piwik_option table. Querying data for each tracking
* request means an extra unnecessary database query for each visitor action. Using
* a cache solves this problem.
*
* **Example**
*
* public function setTrackerCacheGeneral(&$cacheContent)
* {
* $cacheContent['MyPlugin.myCacheKey'] = Option::get('MyPlugin_myOption');
* }
*
* @param array &$cacheContent Array of cached data. Each piece of data must be
* mapped by name.
*/
Piwik::postEvent('Tracker.setTrackerCacheGeneral', array(&$cacheContent));
self::setCacheGeneral($cacheContent);
Common::printDebug("General tracker cache was re-created.");
Tracker::restoreTrackerPlugins();
return $cacheContent;
}