Exemple #1
0
 /**
  * Static function for reporting statistics
  *
  * This function checks whether it should report statistics, based on
  * the current configuation settings. If it should, it creates a new
  * Snapshot object, takes a snapshot, and reports it to headquarters.
  *
  * @return void
  */
 static function check()
 {
     switch (common_config('snapshot', 'run')) {
         case 'web':
             // skip if we're not running on the Web.
             if (!isset($_SERVER) || !array_key_exists('REQUEST_METHOD', $_SERVER)) {
                 break;
             }
             // Run once every frequency hits
             // XXX: do frequency by time (once a week, etc.) rather than
             // hits
             if (rand() % common_config('snapshot', 'frequency') == 0) {
                 $snapshot = new Snapshot();
                 $snapshot->take();
                 $snapshot->report();
             }
             break;
         case 'cron':
             // skip if we're running on the Web
             if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
                 break;
             }
             common_log(LOG_INFO, 'Running snapshot from cron job');
             // We're running from the command line; assume
             $snapshot = new Snapshot();
             $snapshot->take();
             common_log(LOG_INFO, count($snapshot->stats) . " statistics being uploaded.");
             $snapshot->report();
             break;
         case 'never':
             break;
         default:
             common_log(LOG_WARNING, "Unrecognized value for snapshot run config.");
     }
 }