Counting Web Page Hits

I run a web server and get dozens of hits a day. It would be nice to see which pages are the most popular. This easily can be done with a Perl program.

The web.pm Module

Start with a general purpose module that reads and parses the web server log files. In this case, the web server is Apache, and a typical log file looks the following:

 64.246.28.18 ––[14/Apr/2002:04:08:53 –0700] "GET / HTTP/1.1" 200 3329 210.49.177.106 ––[14/Apr/2002:04:15:04 –0700] "GET /not/ HTTP/1.0" 200 1471 210.49.177.106 ––[14/Apr/2002:04:15:16 –0700] "GET /not/prog_1.html HTTP/1.0" 200 835 210.49.177.106 ––[14/Apr/2002:04:15:25 –0700] "GET /not/hint_1.html HTTP/1.0" 200 511 210.49.177.106 ––[14/Apr/2002:04:15:40 –0700] "GET /not/answer_1.html ...

Get Perl for C Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.