Download the PHP package eftec/documentstoreone without Composer

On this page you can find all versions of the php package eftec/documentstoreone. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package documentstoreone

DocumentStoreOne

A document store for PHP that allows multiples concurrencies. It is a minimalist alternative to MongoDB or CouchDB without the overhead of installing a new service.

It also works as a small footprint database.

Packagist Total Downloads [License]() [Maintenance]() [composer]() [php]() [php]() [php]() [Doc]()

Key features

Test

In average, an SMB generates 100 invoices per month. So, let's say that an SMB generates 12000 invoices per decade.

Testing generating 12000 invoices with customer, details (around 1-5 lines per detail) and date on an i7/ssd/16gb/windows 64bits.

mapreduce example

Concurrency test

A test with 100 concurrent test (write and read), 10 times.

Reads (ms) Reads Error
1 100 7471 100 0
2 100 7751 100 0
3 100 7490 100 0
4 100 7480 100 0
5 100 8199 100 0
6 100 7451 100 0
7 100 7476 100 0
8 100 7244 100 0
9 100 7573 100 0
10 100 7818 100 0

Usage

Methods

Constructor($baseFolder,$collection,$strategy=DocumentStoreOne::DSO_AUTO,$server="",$serializeStrategy = false,$keyEncryption = '')

It creates the DocumentStoreOne instance.

strategy type server benchmark
DSO_AUTO It sets the best available strategy (default) depends -
DSO_FOLDER It uses a folder for lock/unlock a document - 0.3247
DSO_APCU It uses APCU for lock/unlock a document - 0.1480
DSO_REDIS It uses REDIS for lock/unlock a document localhost:6379 2.5403 (worst)
DSO_NONE It uses nothing to lock/unlock a document. It is the fastest method but it is unsafe for multiples users 0
strategy type
php it serializes using serialize() function
php_array it serializes using include()/var_export()function. The result could be cached on OpCache because the result is a PHP code file.
json_object it is serialized using json (as object)
json_array it is serialized using json (as array)
csv it serializes using a csv file.
igbinary it serializes using a igbinary file.
none (default value) it is not serialized. Information must be serialized/de-serialized manually

Examples:

Benchmark how much time (in seconds) it takes to add 100 inserts.

isCollection($collection)

Returns true if collection is valid (a sub-folder).

collection($collection)

It sets the current collection

This command could be nested.

Note, it doesn't validate if the collection is correct or exists. You must use isCollection() to verify if it's right.

autoSerialize($value=true,$strategy='php')

It sets if we want to auto serialize the information, and we set how it is serialized. You can also set using the constructor.

strategy type
php it serializes using serialize() function.
php_array it serializes using include()/var_export()function. The result could be cached on OpCache because the result is a php file
json_object it is serialized using json (as object)
json_array it is serialized using json (as array)
csv it serializes using a csv file.
igbinary it serializes using a igbinary file.
none (default value) it is not serialized. Information must be serialized/de-serialized manually

createCollection($collection)

It creates a collection (a new folder inside the base folder). It returns false if the operation fails; otherwise it returns true

insertOrUpdate($id,$document,[$tries=-1])

inserts a new document (string) in the $id indicated. If the document exists, then it's updated.
$tries indicates the number of tries. The default value is -1 (default number of attempts).

If the document is locked then it retries until it is available or after a "nth" number of tries (by default it's 100 tries that equivalent to 10 seconds)

It's faster than insert or update.

insert($id,$document,[$tries=-1])

Inserts a new document (string) in the $id indicated. If the document exists, then it returns false.
$tries indicates the number of tries. The default value is -1 (default number of attempts).

If the document is locked then it retries until it is available or after a "nth" number of tries (by default it's 100 tries that equivalent to 10 seconds)

update($id,$document,[$tries=-1])

Update a document (string) in the $id indicated. If the document doesn't exist, then it returns false
$tries indicates the number of tries. The default value is -1 (default number of attempts).

If the document is locked then it retries until it is available or after a "nth" number of tries (by default it's 100 tries that equivales to 10 seconds)

get($id,[$tries=-1],$default=false)

It reads the document $id. If the document doesn't exist, or it's unable to read it, then it returns false.
$tries indicates the number of tries. The default value is -1 (default number of attempts).

If the document is locked then it retries until it is available or after a "nth" number of tries (by default it's 100 tries that equivalent to 10 seconds)

getFiltered($id,[$tries=-1],$default=false,$condition=[],$reindex=true)

It reads the document $id filtered. If the document doesn't exist, or it's unable to read it, then it returns false.
$tries indicates the number of tries. The default value is -1 (default number of attempts).

If the document is locked then it retries until it is available or after a "nth" number of tries (by default it's 100 tries that equivalent to 10 seconds)

public function appendValue($name,$addValue,$tries=-1)

It adds a value to a document with name $name. The new value is added, so it avoids to create the whole document. It is useful, for example, for a log file.

a) If the value doesn't exist, then it's created with $addValue. Otherwise, it will return true
b) If the value exists, then $addValue is added, and it'll return true
c) Otherwise, it will return false

getNextSequence($name="seq",$tries=-1,$init=1,$interval=1,$reserveAdditional=0)

It reads or generates a new sequence.

a) If the sequence exists, then it's incremented by $interval and this value is returned.
b) If the sequence doesn't exist, then it's created with $init, and this value is returned. c) If the library is unable to create a sequence, unable to lock or the sequence exists but, it's unable to read, then it returns false

You could peek a sequence with $id=get('genseq_') however it's not recommended.

If the sequence is corrupt then it's reset to $init

If you need to reserve a list of sequences, you could use $reserveAdditional

getSequencePHP()

It returns a unique sequence (64bit integer) based on time, a random value and a serverId.

The chances of collision (a generation of the same value) is 1/4095 (per two operations executed every 0.0001 second).

ifExist($id,[$tries=-1])

It checks if the document $id exists. It returns true if the document exists. Otherwise, it returns false.
$tries indicates the number of tries. The default value is -1 (default number of tries).

The validation only happens if the document is fully unlocked.

If the document is locked then it retries until it is available or after a "nth" number of tries (by default it's 100 tries that equivales to 10 seconds)

delete($id,[$tries=-1])

It deletes the document $id. If the document doesn't exist, or it's unable to delete, then it returns false.
$tries indicates the number of tries. The default value is -1 (default number of tries).

If the document is locked then it retries until it is available or after a "nth" number of tries (by default it's 100 tries that equivales to 10 seconds)

select($mask="*")

It returns all the IDs stored on a collection.

It includes locked documents.

copy($idorigin,$iddestination,[$tries=-1])

Copy the document $idorigin in $iddestination

If the document destination exists then its replaced

rename($idorigin,$iddestination,[$tries=-1])

Rename the document $idorigin as $iddestination

If the document destination exists then the operation fails.

fixCast (util class)

It converts a stdclass to a specific class.

It doesn't work with members that are array of objects. The array is kept as stdclass.

DocumentStoreOne Fields

The next fields are public, and they could be changed during runtime

field Type
$database string root folder of the database
$collection string Current collection (subfolder) of the database
$maxLockTime=120 int Maximium duration of the lock (in seconds). By default it's 2 minutes
$defaultNumRetry=100 int Default number of retries. By default it tries 100x0.1sec=10 seconds
$intervalBetweenRetry=100000 int Interval (in microseconds) between retries. 100000 means 0.1 seconds
$docExt=".dson" string Default extension (with dot) of the document
$keyEncryption="" string Indicates if the key is encrypted or not when it's stored (the file name). Empty means, no encryption. You could use md5,sha1,sha256,..

Example:

MapReduce

It could be done manually. The system allows to store a pre-calculated value that could be easily accesses (instead of read all values).

Let's say the next exercise, we have a list of purchases

id customer age sex productpurchase amount
14 john 33 m 33 3
25 anna 22 f 32 1
productcode unitprice
32 23.3
33 30

John purchased 3 products with the code 33. The products 33 costs $23.3 per unit.

Question, how much every customer paid?.

It's a simple exercise, it's more suitable for a relational database (select * from purchases inner join products). However, if the document is long or complex to store in the database then it's here where a document store shines.

customer value
john 69.9
anna 30

Since it's done on code then it's possible to create a hybrid system (relational database+store+memory cache)

Limits

Strategy of Serialization

Let's say we want to serialize the next information:

NONE

The values are not serialized, so it is not possible to serialize an object, array or other structure. It only works with strings.

How values are stored

How values are returned

PHP

The serialization of PHP is one of the faster way to serialize and de-serialize, and it always returns the same value with the same structure (classes, array, fields)

However, the value stored could be long.

How the values are stored:

How the values are returned:

PHP_ARRAY

This serialization generates a PHP code. This code is verbose however, it has some nice features:

How the values are stored:

How the values are returned:

JSON_ARRAY and JSON_OBJECT

Both methods work with JSON for the serialization and de-serialization but the first on returns always an associative array while the other could return an object (stdClass)

Pro:

Cons:

How the values are stored:

How the values are returned:

Control of Error

By default, this library throws errors when an error or exception happens. Some methods allow to avoid throwing errors but most of them could throw an error.

The errors are try/catch catch-ables.

Or you could also use to avoid throwing an exception:

Working with CSV

You can work with CSV as follows:

Version list

Pending


All versions of documentstoreone with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package eftec/documentstoreone contains the following files

Loading the files please wait ....