I Have a web application that will support a large number of connections. Each time a session is created, or a refresh is called, I will run a service that will collect data and store it for viewing. Then using php, read this data from somewhere, and display it back to the user. My question is; If i'm only reading and writing from a single table with 5 columns and 50~100 rows(per user), would it be faster to store this information in flat file(s) and read from it?
Asked
Active
Viewed 410 times
2
-
2The risk here is that you could end up recreating every database functionality. Are you really sure you need only a little subset of those functionalities? Is this risk worth your time as a programmer? – CaNNaDaRk Sep 01 '11 at 12:57
-
I will have to link to a database for authentication, However my service will be 'updating' the records for each active user every _n_ seconds and inactive users will be updated every _n_ minutes.. so it will be continuously updating those records.. not many.. just unending. – rlemon Sep 01 '11 at 13:01
-
possible duplicate of [database vs. flat files](http://stackoverflow.com/questions/2356851/database-vs-flat-files) – ajreal Sep 01 '11 at 13:01
-
2Databases also cache the data in memory. By actually storing them in the filesystem manually, you have to implement this step yourself or your performance will be much lower because of the I/O. Go with a database and save yourself the unneeded troubles. – ZeissS Sep 01 '11 at 13:02
-
Then definitely go with the DB. – NullUserException Sep 01 '11 at 13:02
-
Thanks everyone. I will go with what you are saying and try the database approach. Thanks! – rlemon Sep 01 '11 at 13:04
-
Why would this be voted for close? It's a valid programming question, and it has an answer. Also the duplicate listed is for larger databases / flat files and is a discussion point for a general audience. – rlemon Sep 01 '11 at 17:21
1 Answers
3
You'll only know for sure by benchmarking it, but keep in mind that the developers of the RDBMS systems have already taken care of the necessary optimizations to move data in and out of database tables, and MySQL has a strong API for PHP, supporting transactional writes.
I would go for the database over flat files for sure, but benchmark your own situation.

Michael Berkowski
- 267,341
- 46
- 444
- 390