What is faster, flat files or a MySQL RAM database?

Robin Rodricks picture Robin Rodricks · Sep 17, 2009 · Viewed 7.2k times · Source

I need a simple way for multiple running PHP scripts to share data.

Should I create a MySQL DB with a RAM storage engine, and share data via that (can multiple scripts connect to the same DB simultaneously?)

Or would flat files with one piece of data per line be better?

Answer

gahooa picture gahooa · Sep 17, 2009

Flat files? Nooooooo...

Use a good DB engine (MySQL, SQLite, etc). Then, for maximum performance, use memcached to cache content.


In this way, you have the ease and reliability of sharing data between processes using proven server software that handles concurrency, etc... But you get the speed of having your data cached.

Keep in mind a couple things:

  1. MySQL has a query cache. If you are issuing the same queries repeteadly, you can gain a lot of performance without adding a caching layer.
  2. MySQL is really fast anyway. Have you load-tested to demonstrate it is not fast enough?