TXT file or database?

What should I use in this case (Apache + PHP)? Database or just a TXT file ? My # 1 priority is speed .

Operations

  • Adding New Items
  • Reading items
  • Max. 1,000 entries

Thanks.

Database (MySQL)

+----------+-----+ | Name | Age | +----------+-----+ | Joshua | 32 | | Thomas | 21 | | James | 34 | | Daniel | 12 | +----------+-----+ 

Txt file

 Joshua 32 Thomas 21 James 34 Daniel 12 
+7
database php mysql text-files
source share
11 answers

Have you studied other DHT?

Voldemort Project

Memcached + mysql

Update 1

If you do not have memcached and Voldemort on your servers, you can go to the built-in databases with the key, for example BDB

+2
source share

For speed and optimized memory usage, I would say go with the database. Including an index in a name column is likely to improve performance in a way that would never have been achieved with a text file.

The database has other advantages, such as some sanitation (without breaking separators, newlines, etc.) and less risk of access conflicts when several instances try to read from the table - and differs from the file-based approach, it is limited only the specified entry.

+7
source share

The proposed text file is essentially a database. Writing operations yourself to manipulate it is just to reinvent the wheel, so just use what already exists. 1000 records are pretty small, so using something as simple as SQLite would be nice.

+3
source share

Using a database will be more efficient. You will be able to query and perform operations to select data much easier than if it were in a text file. The text file must be constantly open, closed, and the contents blown up to achieve data iteration or search for strings - this will be slow and painful for the code.

There are classes and ready-made scripts that will allow you to store such data in text files, but in the end this is what the databases were created for, so I would use them.

+1
source share

Just store it in memory if there are only 1000 entries.

+1
source share

With a maximum of 1000 entries containing only columns of names and age, I doubt that there is any significant speed difference between your parameters; probably other factors, such as server load, will dominate your speed.

For simple and reliable access, MySQL may be a little simpler, but with a text file you do not need to configure the MySQL server.

It seems to me that we do not have enough information to give you an educated answer.

0
source share

As mentioned above, there are alternatives to this problem. The power of the database can be useful (after all, you don’t want to code these functions yourself when you can do something else), but you don’t want to overload.

SQLite may be worth a look, as it can be thought of as a file (no worries about the server), but it gives you SQL query capabilities.

You can also try something like Memcached as a cache on top of any level of data storage you choose.

0
source share

If speed is really important, I can suggest var_export to create a .php file that can be downloaded using PHP. As long as the number of reads in the record is large enough and if APC , the PHP file will be able to use the APC operating code cache. It will be faster than anything else, because the data will be loaded initially as PHP instead of going through the intermediate level (memcache, mysql, etc.).

0
source share

SQLite Small fast database. http://www.sqlite.org/

Integrated with PHP installations these days. http://php.net/manual/en/book.sqlite.php

Gives you options:

And if you really want speed to consider nginx with fast-cgi php.

0
source share

I would definitely recommend a text file database any day. Firstly, databases do a lot of optimization when accessing data, so you don’t have to worry about performance. Secondly, you still have many opportunities. You can use the SQL language to do things like:

  • Select all customers whose age is greater than or equal to 18.
  • Get the number of products you sold.
  • Get the total revenue from the products you sold.
  • Get the average price for all your products.
  • Get a list of customers who live in a specific area.

... and much, much more, with simple SQL statements. Trying to encode everything for a text file would be counterproductive and much less flexible. With the database you get it all for free.

0
source share

This is very risky, but you can dynamically generate a PHP file. If you will mainly read from this file, then this will be the fastest way for small records with a limit of 1000.

0
source share

All Articles