#!/usr/bin/php = '400') continue; $total++; // Attempt to determine for which product was the request. if (!preg_match(REGEX_PRODUCT, $match[4], $match_product)) { continue; } // Remove empty match groups and select non-all match. $values = array_filter($match_product); $product = str_replace('factory', 'tumbleweed', strtolower(next($values))); if (!isset($total_product[$product])) $total_product[$product] = 0; $total_product[$product] += 1; if (count($match) == 10 && $match[8] != '-') { $uuid = $match[8]; if (!isset($unique_product[$product])) $unique_product[$product] = []; if (!isset($unique_product[$product][$uuid])) { $unique_product[$product][$uuid] = [ 'count' => 0, 'flavor' => $match[9], 'ip' => $match[1], ]; } $unique_product[$product][$uuid]['count'] += 1; } if (preg_match(REGEX_IMAGE, $match[4], $match_image)) { // Remove empty match groups and select non-all match. $values = array_filter($match_image); $image = next($values); if (!isset($total_image_product[$product])) $total_image_product[$product] = []; if (!isset($total_image_product[$product][$image])) $total_image_product[$product][$image] = 0; $total_image_product[$product][$image] += 1; } } $position = ftell($handle); fclose($handle); error_log('processed ' . number_format($position) . ' bytes'); error_log('found ' . number_format($total) . ' requests across ' . number_format(count($total_product)) . ' products'); ksort($total_product); ksort($unique_product); ksort($unique_product_flavor); if ($position) { echo json_encode([ 'total' => $total, 'total_product' => $total_product, 'unique_product' => $unique_product, 'total_image_product' => $total_image_product, 'total_invalid' => $total_invalid, 'bytes' => $position, ]) . "\n"; // JSON_PRETTY_PRINT for debugging. }