#!/usr/bin/php <?php $lrFpIn = fopen("php://stdin", 'r'); $lcDomain = ''; $laCount = $laTime = array(); while ($lcLine = trim(fgets($lrFpIn))) { $la = explode(' ', $lcLine); if ($lcDomain != $la[0]) { if ($lcDomain) { finish($lcDomain, $laCount, $laTime); } $lcDomain = $la[0]; $laCount = $laTime = array(); } $laCount[$la[1]]++; $laTime[$la[1]] += round($la[2]); } finish($lcDomain, $laCount, $laTime); fclose($lrFpIn); exit; function finish($pcDomain , &$paCount, &$paTime) { arsort($paTime); reset($paTime); foreach ($paTime as $lcURL => $lnTime) { echo "$pcDomain ".$paCount[$lcURL]." $lnTime\n"; } } ?>