12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace Cas\Controller\CmdLine;
- use Cas\Dao\LotteryPvUvLog;
- use KIF\Core\Config;
- /**
- * 分析前一天 /log/Pass_log 访问日志
- *
- * php index.php -cCmdLine_RunLog -aRun
- */
- class RunLog extends Controller {
- public function doDefault() {
- }
-
- /**
- * 跑出前一天的活动的 IP PV UV
- * php /export/manager/v2/v2_cas/www/index.php -cCmdLine_RunLog -aRun
- */
- public function doRun() {
- $objDLotteryPvUvLog = new LotteryPvUvLog ();
-
- # 获取昨天目录下 所有的
- $Y = date('Y',strtotime('-1 day today'));
- $m = date('m',strtotime('-1 day today'));
- $dir =Config::getInstance ()->get ( 'Log_Path' ).DIRECTORY_SEPARATOR.$Y.DIRECTORY_SEPARATOR.$m.DIRECTORY_SEPARATOR;
-
- $list = scandir($dir);
- $thisList = array();
- $name = 'Pass_log_'.date('Y_m_d',strtotime('-1 day today'));
- foreach($list as $data){
- if(strpos($data, $name) !== false){
- $thisList[$data] = $dir.$data;
- }
- }
- $allData = array();
- $eventsArr = array();
- $tmpEventsIp = array();
- $tmpEventsUV = array();
- foreach($thisList as $thisDir){
- $string = file_get_contents($thisDir);
- $d = explode("\n", $string);
- foreach($d as $key=> $s){
- if($s){
- $arr = unserialize($s);
-
- if(isset($eventsArr[$arr['event_id']]['pv'])){
- $eventsArr[$arr['event_id']]['pv'] ++;
- }else{
- $eventsArr[$arr['event_id']]['pv'] = 1;
- }
-
- $tmpEventsIp[$arr['event_id']][$arr['ip']] = $arr['ip'];
-
- $tmpEventsUV[$arr['event_id']][$arr['ip'].$arr['user_agent']] = $arr['ip'].$arr['user_agent'];
-
- $allData[] = $arr;
- }
- }
- }
-
-
-
- # PV
- # IP
- foreach($tmpEventsIp as $events_id => $ips){
- $eventsArr[$events_id]['ip'] = count($ips);
- }
-
- # UV
- foreach($tmpEventsUV as $events_id => $vps){
- $eventsArr[$events_id]['uv'] = count($vps);
- }
-
- foreach($eventsArr as $events_id => $data){
- $info = array();
- $info ['events_id'] = $events_id ;
- $info ['pv_num'] = $data['pv'] ;
- $info ['uv_num'] = $data['uv'] ;
- $info ['ip_num'] = $data['ip'] ;
- $info ['date'] = strtotime('-1 day today');
-
- $objDLotteryPvUvLog->add ( $info ,LotteryPvUvLog::PARAM_CREATE_ACTION_ONDUPLICATE);
-
- }
-
-
-
- }
- }
|