Fast database as an alternative to PHP array

I have an array containing my reference variables and in my scripts I need to catch one or two variables. On the current system, I have to include the entire array (and its elements) to use a single element. It looks like using a database is better for two reasons:

  • One record is read instead of the whole array
  • Variables can be easily edited

However, there is a big drawback to using the database: every time php is started, we have to establish a connection to the database.

Since simple database systems like SQLite don't have a server, persistent_connection is not like extended database servers like mysql

.

In action

$db = new SQLite3('mysqlitedb.db');

      

takes longer (and consumes more resources) than

include 'array.php';

      

Is there any solution for the underlying database system (fast connect) to be a replacement for PHP array and include

file?

In other words, I want a simple fast connect database system comparable to fopen

. However, even CDB

which is incredibly fast, it is not fast enough on the initial connection.

+3


source to share


2 answers


By including the static array file, you are essentially doing what the caching systems do when they fetch the result from the database. You load the preprocessed result directly from disk.

All database connections have some overhead (more than including rendering, of course). You use the database when you need live support for your data, but this comes with application overhead.



If you are not worried about data persistence, you may need to use a caching system such as APC, memcached, or redis.

+4


source


Have you considered caching variables? You can use APC or Memcached for this purpose. They will be faster than a database since the data is stored in RAM and not on disk.



It will still be slower than just an array.

+1


source







All Articles