Skip to the content.

PHP-mdbm

Build Stats PHP-mdbm ver. License Y! mdbm ver.
Build Status GitHub version License: MIT GitHub version

Table of Contents

API

Almost Useful APIs Support.

Not Supported APIs

Unfortunately, the following list are not supported on now.

Group API
Record Iteration mdbm_iterate
Data Management mdbm_clean, mdbm_prune, mdbm_set_cleanfunc
Statistics mdbm_chunk_iterate
Cache and Backing Store mdbm_set_backingstore
Import and Export mdbm_cdbdump_to_file, mdbm_cdbdump_trailer_and_close, mdbm_cdbdump_add_record, mdbm_dbdump_to_file, mdbm_dbdump_trailer_and_close, mdbm_dbdump_add_record, mdbm_dbdump_export_header, mdbm_dbdump_import_header, mdbm_dbdump_import, mdbm_cdbdump_import

If you want them, please feel free to raise an issue

Deprecated APIs

API STATUS COMMENT
mdbm_save DEPRECATED mdbm_save is only supported for V2 MDBMs.
mdbm_restore DEPRECATED mdbm_restore is only supported for V2 MDBMs.
mdbm_sethash DEPRECATED Legacy version of mdbm_set_hash() This function has inconsistent naming, an error return value. It will be removed in a future version.

Only a V2 implementation

API STATUS COMMENT
mdbm_stat_all_page V3 not supported There is only a V2 implementation. V3 not currently supported.
mdbm_stat_header V3 not supported There is only a V2 implementation. V3 not currently supported.

Support Two Versions Compatibility

PHP

Version Support Test
5.2.x ~ 5.6.x yes always
7.x yes always
8.x yes always

MDBM

branch or release ver. Support Test Comment
master yes always  
4.x yes always  

Install

MDBM

php-mdbm

Use the composer (packagist)

See the composer documentation for use composer

composer require torden/php-mdbm

Use the source code

git clone https://github.com/torden/php-mdbm
Or Download the tarball (tag or release)
wget https://github.com/torden/php-mdbm/archive/vX.X.X.tar.gz
tar xvzf vX.X.X.tar.gz
Compile
cd php-mdbm/src/
$PHP_INSTALLED_PATH/bin/phpize
./configure --with-php-config=$PHP_INSTALLED_PATH/bin/php-config --with-mdbm=/usr/local/mdbm/
make
#make test TESTS='-q -m'
#make test TESTS='-q'
make install
Configuration
echo "extension=mdbm.so" >> php.ini
Check
$PHP_INSTALLED_PATH/bin/php -i | fgrep -i mdbm
...
mdbm
MDBM Support => enable
MDBM API Version => 4
PHP MDBM Version => 0.1.0
...

Example

See the documentation for more details.

Benchmark

The following is results of PHP-mdbm vs PHP SQlite3 benchmarks for simple data storing and random fetching.

See the Source Code.

Prepare for a Benchmark

cd php-mdbm/src/benchmark/
composer install

Spec

Host

Type Spec
CPU Inte i-7
RAM DDR4 32G
HDD Nvme M.2 SSD

VM

Type Spec
Machine VM(VirtualBox)
OS Ubuntu 17.10.1 (Artful Aardvark)
CPU 2 vCore
RAM 8G

Software

Type Version Comment
PHP 7.0.26
php-mdbm v0.1.0
mdbm master branch
SQLite3 3.19.3 Async, Transaction, journal_mode = wal

Simple INSERTs

php src/mdbm_simple_store.php -live
 Created by B. van Hoekelen version 2.3.2 PHP v7.0.26
 Max memory 128M, max execution time unlimited on 2018-01-21 01:33:02

   Label                                                         Time        Memory        Peak
---------------------------------------------------------------------------------------------------
 > Calibrate point                                               2.86 μs |    0.00 KB |    2.00 MB
 > mdbm store(number, number) :: 100,000                       297.88 ms |    0.00 KB |    2.00 MB
 > mdbm store(string, string) :: 100,000                       329.36 ms |    0.00 KB |    2.00 MB
 > mdbm store(number, number) :: 1,000,000                       2.94  s |    0.00 KB |    2.00 MB
 > mdbm store(string, string) :: 1,000,000                       3.36  s |    0.00 KB |    2.00 MB
 > mdbm store(number, number):: 10,000,000                       70.4  s |    0.00 KB |    2.00 MB
 > mdbm store(string, string) :: 10,000,000                    125.46  s |    0.00 KB |    2.00 MB
---------------------------------------------------------------------------------------------------
   Total 7 taken                             01-21 01:36:25    202.78  s      0.00 KB      2.00 MB

Simple Random FETCHs

php src/mdbm_simple_fetch.php -live
 Created by B. van Hoekelen version 2.3.2 PHP v7.0.26
 Max memory 128M, max execution time unlimited on 2018-01-21 01:37:49

   Label                                                         Time        Memory        Peak
---------------------------------------------------------------------------------------------------
 > Calibrate point                                               4.05 μs |    0.00 KB |    2.00 MB
 > mdbm random fetch(number) :: 100,000                        140.18 ms |    0.00 KB |    2.00 MB
 > mdbm random fetch(string) :: 100,000                        161.95 ms |    0.00 KB |    2.00 MB
 > mdbm random fetch(number) :: 1,000,000                        1.44  s |    0.00 KB |    2.00 MB
 > mdbm random fetch(string) :: 1,000,000                        1.63  s |    0.00 KB |    2.00 MB
 > mdbm random fetch(number):: 10,000,000                       15.07  s |    0.00 KB |    2.00 MB
 > mdbm random fetch(number) :: 10,000,000                      16.97  s |    0.00 KB |    2.00 MB
---------------------------------------------------------------------------------------------------
   Total 7 taken                             01-21 01:38:24     35.42  s      0.00 KB      2.00 MB

Simple Random FETCHs with Use the Preload API

php src/mdbm_simple_preload_fetch.php -live
 Created by B. van Hoekelen version 2.3.2 PHP v7.0.26
 Max memory 128M, max execution time unlimited on 2018-01-21 01:39:36

   Label                                                         Time        Memory        Peak
---------------------------------------------------------------------------------------------------
 > Calibrate point                                               4.05 μs |    0.00 KB |    2.00 MB
 > mdbm::preload random fetch(number) :: 100,000               138.52 ms |    0.00 KB |    2.00 MB
 > mdbm::preload random fetch(string) :: 100,000               154.26 ms |    0.00 KB |    2.00 MB
 > mdbm::preload random fetch(number) :: 1,000,000                1.4  s |    0.00 KB |    2.00 MB
 > mdbm::preload random fetch(string) :: 1,000,000               1.58  s |    0.00 KB |    2.00 MB
 > mdbm::preload random fetch(number):: 10,000,000              14.83  s |    0.00 KB |    2.00 MB
 > mdbm::preload random fetch(number) :: 10,000,000             16.73  s |    0.00 KB |    2.00 MB
---------------------------------------------------------------------------------------------------
   Total 7 taken                             01-21 01:40:11     34.83  s      0.00 KB      2.00 MB

SQLite3

Simple INSERTs

php src/sqlite3_simple_store.php -live
PRAGMA synchronous=OFF;
pragma journal_mode = wal;
Transaction(BEGIN,COMMIT)

 Created by B. van Hoekelen version 2.3.2 PHP v7.0.26
 Max memory 128M, max execution time unlimited on 2018-01-22 00:44:56

   Label                                                         Time        Memory        Peak
---------------------------------------------------------------------------------------------------
 > Calibrate point                                               4.05 μs |    0.00 KB |    2.00 MB
 > sqlite3 insert(number, number) :: 100,000                    761.78 ms |    0.00 KB |    2.00 MB
 > sqlite3 insert(string, string) :: 100,000                      1.17  s |    0.00 KB |    2.00 MB
 > sqlite3 insert(number, number) :: 1,000,000                    7.93  s |    0.00 KB |    2.00 MB
 > sqlite3 insert(string, string) :: 1,000,000                   12.29  s |    0.00 KB |    2.00 MB
 > sqlite3 insert(number, number):: 10,000,000                   80.24  s |    0.00 KB |    2.00 MB
 > sqlite3 insert(string, string) :: 10,000,000                 127.54  s |    0.00 KB |    2.00 MB
---------------------------------------------------------------------------------------------------
   Total 7 taken                             01-22 01:00:25    229.93  s      0.00 KB      2.00 MB

Simple Random FETCHs

php src/sqlite3_simple_fetch.php -live
PRAGMA synchronous=OFF;
pragma journal_mode = wal;

 Created by B. van Hoekelen version 2.3.2 PHP v7.0.26
 Max memory 128M, max execution time unlimited on 2018-01-22 01:23:53

   Label                                                         Time        Memory        Peak
---------------------------------------------------------------------------------------------------
 > Calibrate point                                               4.05 μs |    0.00 KB |    2.00 MB
 > sqlite3 random fetch(number) :: 100,000                       2.16  s |    0.00 KB |    2.00 MB
 > sqlite3 random fetch(string) :: 100,000                       3.16  s |    0.00 KB |    2.00 MB
 > sqlite3 random fetch(number) :: 1,000,000                    25.94  s |    0.00 KB |    2.00 MB
 > sqlite3 random fetch(string) :: 1,000,000                    34.84  s |    0.00 KB |    2.00 MB
 > sqlite3 random fetch(number):: 10,000,000                   275.47  s |    0.00 KB |    2.00 MB
 > sqlite3 random fetch(string) :: 10,000,000                  397.42  s |    0.00 KB |    2.00 MB
---------------------------------------------------------------------------------------------------
   Total 7 taken                             01-22 01:36:12    738.99  s      0.00 KB      2.00 MB

Please feel free. I hope it is helpful for you.