Webiter
Webiter

Reputation: 119

Flatfile Management in PHP

What are the restrictions on the length of a flatfile db? How are the number of entries on a flatfile page controlled?

Upvotes: 1

Views: 593

Answers (2)

Drew Chapin
Drew Chapin

Reputation: 7989

You will only be limited by the amount of free-space on the servers hard drive and the file system used on the drive. For example if it's ext3 with a 4KiB block size then you'd be limited to 16TiB. When doing a database in a flat-file, you are the designer of how the database is formatted. Most people do entries by line, some do spaces. It will be up to you and your needs. Keep in mind though that for a larger database, any SQL server (e.g. MySQL, MSSQL, PostgreSQL, etc.) is going to give you much better performance.

Here is an example of using a flat-file as a database: http://www.designdetector.com/archives/04/10/FlatFileDatabaseDemo.php#demo

Upvotes: 1

user1093284
user1093284

Reputation:

Limits for flat file databases depend on the server's file system. Nowadays, you can use huge flat-file databases that go gigabyte in size. But remember that there are "locking" issues when you read-and-write to such "databases" while others are reading and/or writing to them too. You wouldn't be the first one to lose all data in such a flat-file database due to a "race condition" gone wrong.

SQLite2/SQLite3 and MySQL all handle such problems in their own way and most of the time they handle it more safe than ye average fread/fwrite implementation using locking functions like PHP's "flock" (as it's only "advisory" on some linux systems and might simply not work). That's why people opt-in for such database servers. It spares you the trouble of worrying about locking issues and provides you with a whole set of database functions to learn and use! ;)

Upvotes: 1

Related Questions