我想通過IP連接並且具有播放狀態從日誌文件中獲取活動連接的數量(實時),相反,它給我的狀態播放IP總數。這個數字根本沒有減少。一旦添加新的IP,就會持續增加。我該如何解決它?在這裏我的代碼:在php中解析ip地址
$stringToParse = file_get_contents('wowzamediaserver_access.log');
preg_match_all('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $stringToParse, $matchOP);
echo "Number of connections: ".sizeof(array_unique($matchOP[0]));
這裏是LOG:
2013-10-30 14:54:36 CET stop stream INFO 200 account1 - _defaultVHost_ account1 _definst_ 149.21 streamURL 1935 fullStreamURL IP_ADDRESS_1 http (cupertino) -
2013-10-30 14:56:12 CET play stream INFO 200 account2 - _defaultVHost_ account1 _definst_ 149.21 streamURL 1935 fullStreamURL IP_ADDRESS_2 rtmp (cupertino) -
2013-10-30 14:58:23 CET stop stream INFO 200 account2 - _defaultVHost_ account1 _definst_ 149.21 streamURL 1935 fullStreamURL IP_ADDRESS_2 rtmp (cupertino) -
2013-10-30 14:58:39 CET play stream INFO 200 account1 - _defaultVHost_ account1 _definst_ 149.21 streamURL 1935 fullStreamURL IP_ADDRESS_1 http (cupertino) -
2013-10-30 14:59:12 CET play stream INFO 200 account2 - _defaultVHost_ account1 _definst_ 149.21 streamURL 1935 fullStreamURL IP_ADDRESS_2 rtmp (cupertino) -
我希望能夠算IP,只要它有一個「播放」狀態,只要它的「STOP不要指望它「
2013-10-30 14:59:00 CET play stream INFO 200 tv2vielive - _defaultVHost_ tv2vielive _definst_ 0.315 [any] 1935 rtmp://tv2vie.zion3cloud.com:1935/tv2vielive 78.247.255.186 rtmp http://www.tv2vie.org/swf/flowplayer-3.2.16.swf WIN 11,7,700,202 92565864 3576 3455 1 0 0 0 tv2vielive - - - - - rtmp://tv2vie.zion3cloud.com:1935/tv2vielive/tv2vielive rtmp://tv2vie.zion3cloud.com:1935/tv2vielive/tv2vielive - rtmp://tv2vie.zion3cloud.com:1935/tv2vielive -
2013-10-30 14:59:04 CET stop stream INFO 200 tv2vielive - _defaultVHost_ tv2vielive _definst_ 4.75 [any] 1935 rtmp://tv2vie.zion3cloud.com:1935/tv2vielive 78.247.255.186 rtmp http://www.tv2vie.org/swf/flowplayer-3.2.16.swf WIN 11,7,700,202 92565864 3576 512571 1 7222 0 503766 tv2vielive - - - - - rtmp://tv2vie.zion3cloud.com:1935/tv2vielive/tv2vielive rtmp://tv2vie.zion3cloud.com:1935/tv2vielive/tv2vielive - rtmp://tv2vie.zion3cloud.com:1935/tv2vielive -
任何解決方案?我甚至嘗試了第一個答案解決方案,但獲得「0」播放連接。
$stringToParse = file_get_contents('wowzamediaserver_access.log');
$pattern = '~^.* play.* (([0-9]{1,3}+\.){3,3}[0-9]{1,3}).*$~m';
preg_match_all($pattern, $stringToParse, $matches);
echo count($matches[1]) . ' play actions';
但每當我用我的代碼:
$stringToParse = file_get_contents('wowzamediaserver_access.log');
preg_match_all('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $stringToParse, $matchOP);
echo "Number of connections: ".sizeof(array_unique($matchOP[0]));
我收到「連接數:XXXXX(IPS的實際計數) 我擔心的是,我只需要IP地址的使用計數。播放狀態如果IP切換到STOP那麼它不會算
對不起,我忘了添加日誌: – user2938780
我該如何附加文件?想要附上日誌 – user2938780
您無法在此平臺上附加文件。張貼文件摘錄。 – ComFreek