Looking for real-time feedback as to where Web traffic is coming from, but don't want to deal with the overhead of writing to a database or text file on every request like Refer and ShortStat?
Here's a simple PHP script I use to grab the most recent referrers from Apache's logs:
<?php
$refs =
`tail -5000 /var/log/apache/centricle.com/access.log \
| cut -d '"' -f 4 \
| grep -v '^-\|http://\(www.\)\?centricle' \
| tac`;
echo "<pre>$refs</pre>";
?>
For those who don't spend much time on the command line, here's a quick explanation of what's happening:
tail grabs the last 5000 lines from
access.log, and hands them off to cut, which
finds the 4th field (as delimited by a double quote), and feeds it
to grep. If that field doesn't begin with
a single dash (-), 'http://centricle', or 'http://www.centricle',
it's added to a list that's passed to tac,
which prints the list in reverse.