Writing to a file can cause problems with concurrent users. If you insert into the database instead, you can let the database itself process the queue. If you run out of connections, this is easy to track, and you can see the load on db as you go.
Inserting into the database will be less resource intensive than adding to the file. Having said that, you will need a rather large load in order to take effect - but with the database you have an assembly in the request queue to ease the good part of the simultaneous stress.
When you send a request to the database, it actually goes into the queue for processing. It just cannot be executed if there is a timeout in your PHP code (basically, PHP is suggested to refuse waiting for a db response), and you can control this using the PHP and Apache settings), so you have a fantastic built-in buffer .
source share