4 ms·
I'm curious as to why you chose to stick code into your web application to explicitly insert log entries into a database rather than using the built in logs tha
by jasonkester 15y ago
I'm curious as to why you chose to stick code into your web application to explicitly insert log entries into a database rather than using the built in logs that the server provides.
After all, the web logs that Apache spits out match your schema almost identically. They're perfectly parseable and have the advantage of being parseable at intervals (possibly from a different server) rather than forcing an insert from every page load.
By doing things this way, you essentially remove the ability to scale the application that's being logged. You're doing at least one database insert per page load, thus destroying any gains you might have seen from caching the content you're displaying. And of course, you can't actually cache anyway, since you need to actually run the PHP script for the page in question so that it will fire the database insert to register a hit.
So yeah, I'd suggest dropping that step and just having a worker swing by every once in a while, pull up the logfile, see what's new and bulk insert it into your database. Preferably, with said database and said worker all living on another machine so that they don't bog your production box.
- rachelbythebay 15y agoParsing Apache logs is not the answer. Keeping things in a sensible format is the beginning of the answer. Parsing a "line like this" is "\"harder than it looks\"".
- gst 15y agoParsing Apache logs isn't hard. There's a well-defined spec for them. Of course you have to keep track of stuff like escaping, but that's pretty trivial.
- rachelbythebay 15y agoNo, it actually is difficult. I put this question forth to a bunch of people, and lots of them tripped over something. I'm beginning to think it's a decent "weed-out" question.
- latitude 15y agoI hear you, thanks. It's a pet project and switching to the cron job or just tail'ing the log file is a trivial change, just as you said. Doing it directly from the page is just easier for now.