Forum Moderators: coopster

Message Too Old, No Replies

PHP based log overloading MySQL server

         

thing3b

10:50 pm on Feb 27, 2008 (gmt 0)

10+ Year Member



I am having problems with my database occasionally saying "Too many connections". I have designed my script to be quite easy on the database, it will cache results when ever possible and close all database connections.

My problem is that I want to log details of each request and get these details into a MySQL database. It seems as if the logging directly to MySQL is causing it to overload.

I can not use the Apache Log files instead as some of the data I wish to log is only available when PHP is running.

I can not / will not change the max number of connections for MySQL.

Does anyone have any ideas on how I can write the logging script so that it does not need to connect to the database for every request?

jatar_k

12:09 am on Feb 28, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I guess it depends whether you have your own server but you can get php variables into apache logs [webmasterworld.com]

you could also take a look at syslog [php.net]

you could also try a text file as a log and use a cron to move it in chunks to mysql

thing3b

10:12 am on Feb 28, 2008 (gmt 0)

10+ Year Member



Ok, so if I log to a file first, and then later put it into a database, what is the best format to write the file:

- SQL so that it is ready to go into the database (though I am not sure about new lines, or if this is secure)
- Serialized so that it can be deserialized as an object that adds itself to the database (one per line)
- CSV (comma separated) so that it takes up less room in the file, but I need to process it more.

jatar_k

2:43 pm on Feb 28, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



any of the above, all about preference

the secondary processing is where you need to do the work, the actual logging code needs to be lightning fast, it's a grab data and dump to file, the fancy stuff can be done on insert to the db