Esempio n. 1
0
 function afterRequest()
 {
     $attr = ['datetime' => gmdate(DATE_MYSQL, round_time(time(), self::TIME_INTERVAL, PHP_ROUND_DOWN)), 'action' => Yii::app()->request->requestUri];
     if (!StatRequest::model()->findByAttributes($attr)) {
         $stat = new StatRequest();
         $stat->setAttributes($attr, false);
         $stat->save();
     }
     $time = (int) (Yii::getLogger()->getExecutionTime() * 1000);
     StatRequest::model()->updateByPk($attr, ['count' => new CDbExpression('count + 1'), 'time_min' => new CDbExpression("least(time_min, {$time})"), 'time_max' => new CDbExpression("greatest(time_max, {$time})"), 'time_last' => $time, 'time_total' => new CDbExpression("time_total + {$time}")]);
 }
 public function actionClear()
 {
     $table = StatRequest::model()->tableName();
     StatRequest::model()->getDbConnection()->createCommand("truncate table {$table}")->execute();
     $this->renderJson();
 }
 public function actionDeleteOld()
 {
     StatRequest::model()->deleteAll('datetime < date_sub(date_sub(utc_timestamp(), interval 1 day), interval 2 hour)');
 }
Esempio n. 4
0
 public static function statDayList()
 {
     return StatRequest::model()->findAll(['select' => ['date(datetime) as datetime', 'action', 'sum(count) as count', 'min(time_min) as time_min', 'max(time_max) as time_max', 'sum(time_total) as time_total', 'time_last as time_last'], 'condition' => implode(' and ', ['datetime > date_sub(utc_timestamp(), interval 1 day)']), 'group' => 'action']);
 }