Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP logs - mysql vs file

Tags:

php

logging

I am in the process of setting up user action logging for my PHP site.

Would you recommend storing them in mysql or in text/log files?

like image 207
Nico Burns Avatar asked Jul 18 '09 18:07

Nico Burns


2 Answers

Depends on what you want to do with those, I'd say :

  • If you need to get data from the logs, storing them in MySQL might help
  • If you only need to have some data you almost never use (but need in case of something illegal is done on your site, or stuff like that), a file might be well enough

To not slow things down too much, you can also use both (I've used that on some websites with a bit of traffic, where it wouldn't have been wise to store data in DB immediatly) :

  • during the day, store the logs in a file
  • and once a day (or once an hour, you get the idea), use a batch to parse those files, and put the data in Database

This way, you don't insert data in DB all the time ; and you can (provided a day or an hour has passed) do all the queries you need

like image 200
Pascal MARTIN Avatar answered Sep 26 '22 02:09

Pascal MARTIN


I would recommend using something like Zend_Log to abstract from the actual 'physical' logging. That way you can always change backends later very easily, in case your situation changes for some reason or another.

like image 33
n3rd Avatar answered Sep 26 '22 02:09

n3rd