https://github.com/fire015/flintstone
A key/value database store using flat files for PHP.
https://github.com/fire015/flintstone
database-store flat-files flintstone key-value php
Last synced: 28 days ago
JSON representation
A key/value database store using flat files for PHP.
- Host: GitHub
- URL: https://github.com/fire015/flintstone
- Owner: fire015
- License: mit
- Created: 2011-06-16T10:57:23.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2023-07-09T09:13:02.000Z (over 2 years ago)
- Last Synced: 2024-05-18T17:04:28.197Z (over 1 year ago)
- Topics: database-store, flat-files, flintstone, key-value, php
- Language: PHP
- Homepage:
- Size: 144 KB
- Stars: 285
- Watchers: 19
- Forks: 35
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
Flintstone
==========
[](https://packagist.org/packages/fire015/flintstone)
[](https://travis-ci.com/github/fire015/flintstone)
A key/value database store using flat files for PHP.
Features include:
* Memory efficient
* File locking
* Caching
* Gzip compression
* Easy to use
### Installation
The easiest way to install Flintstone is via [composer](http://getcomposer.org/). Run the following command to install it.
```
composer require fire015/flintstone
```
```php
'/path/to/database/dir/']);
```
### Requirements
- PHP 7.3+
### Data types
Flintstone can store any data type that can be formatted into a string. By default this uses `serialize()`. See [Changing the formatter](#changing-the-formatter) for more details.
### Options
|Name |Type |Default Value |Description |
|--- |--- |--- |--- |
|dir |string |the current working directory |The directory where the database files are stored (this should be somewhere that is not web accessible) e.g. /path/to/database/ |
|ext |string |.dat |The database file extension to use |
|gzip |boolean |false |Use gzip to compress the database |
|cache |boolean or object |true |Whether to cache `get()` results for faster data retrieval |
|formatter |null or object |null |The formatter class used to encode/decode data |
|swap_memory_limit |integer |2097152 |The amount of memory to use before writing to a temporary file |
### Usage examples
```php
'/path/to/database/dir/']);
// Set a key
$users->set('bob', ['email' => 'bob@site.com', 'password' => '123456']);
// Get a key
$user = $users->get('bob');
echo 'Bob, your email is ' . $user['email'];
// Retrieve all key names
$keys = $users->getKeys(); // returns array('bob')
// Retrieve all data
$data = $users->getAll(); // returns array('bob' => array('email' => 'bob@site.com', 'password' => '123456'));
// Delete a key
$users->delete('bob');
// Flush the database
$users->flush();
```
### Changing the formatter
By default Flintstone will encode/decode data using PHP's serialize functions, however you can override this with your own class if you prefer.
Just make sure it implements `Flintstone\Formatter\FormatterInterface` and then you can provide it as the `formatter` option.
If you wish to use JSON as the formatter, Flintstone already ships with this as per the example below:
```php
__DIR__,
'formatter' => new JsonFormatter()
]);
```
### Changing the cache
To speed up data retrieval Flintstone can store the results of `get()` in a cache store. By default this uses a simple array that only persist's for as long as the `Flintstone` object exists.
If you want to use your own cache store (such as Memcached) you can pass a class as the `cache` option. Just make sure it implements `Flintstone\Cache\CacheInterface`.