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.
source to share
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.
source to share