Search code examples
phpmysqlcsvanalytics

What's the most efficient way to record details on page hits


We have a microsite being advertised in a national newspaper as part of the deal they require the following information for every page served to be provided as CSV or similar:

  • Time of page served
  • Date of page served
  • Full URL served
  • Session ID

I really have no idea of the number of visitors expected but it could be fairly high, so the question is; what is the best and most efficient way to do this?

The site is static but I can use PHP or whatever. Am I likely to run into trouble just adding these details to a MySQL database each time a page is served?


Solution

  • Well, first of all, i have no idea why do you want to store required data not already in desired format but store in in SQL first and then convert to CSV.

    Especially if you site is static, so, you will need to employ PHP somehow to do it.
    but okay, even if you're gonna employ PHP, using sql instead of CSV still looks nonsense to me.

    Your web-server most likely already logs almost everything you need, and with minor tuning will be able to log session id too.

    So, if your server happen to be Apache, most efficient solution would be just custom access log, http://httpd.apache.org/docs/current/mod/mod_log_config.html

    it's gonna be like

    LogFormat "\"%t\", \"%f\", \"%{PHPSESSID}C\"" csv
    CustomLog logs/access_log csv
    

    and just set up your cron to send this log by email every day

    Please note that conditional logging should be probably used too, to limit logging to html pages only. I never used it nor tested but according to docs it could be

    SetEnvIf Request_URI "/$" logable
    SetEnvIf Request_URI "\.html$" logable
    CustomLog logs/access_log csv env=logable