Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A key/value database store using flat files for PHP.

License

NotificationsYou must be signed in to change notification settings

fire015/flintstone

Repository files navigation

Total DownloadsBuild Status

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 viacomposer. Run the following command to install it.

composer require fire015/flintstone
<?phprequire'vendor/autoload.php';useFlintstone\Flintstone;$users =newFlintstone('users', ['dir' =>'/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 usesserialize(). SeeChanging the formatter for more details.

Options

NameTypeDefault ValueDescription
dirstringthe current working directoryThe directory where the database files are stored (this should be somewhere that is not web accessible) e.g. /path/to/database/
extstring.datThe database file extension to use
gzipbooleanfalseUse gzip to compress the database
cacheboolean or objecttrueWhether to cacheget() results for faster data retrieval
formatternull or objectnullThe formatter class used to encode/decode data
swap_memory_limitinteger2097152The amount of memory to use before writing to a temporary file

Usage examples

<?php// Load a database$users =newFlintstone('users', ['dir' =>'/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 implementsFlintstone\Formatter\FormatterInterface and then you can provide it as theformatter option.

If you wish to use JSON as the formatter, Flintstone already ships with this as per the example below:

<?phprequire'vendor/autoload.php';useFlintstone\Flintstone;useFlintstone\Formatter\JsonFormatter;$users =newFlintstone('users', ['dir' =>__DIR__,'formatter' =>newJsonFormatter()]);

Changing the cache

To speed up data retrieval Flintstone can store the results ofget() in a cache store. By default this uses a simple array that only persist's for as long as theFlintstone object exists.

If you want to use your own cache store (such as Memcached) you can pass a class as thecache option. Just make sure it implementsFlintstone\Cache\CacheInterface.

About

A key/value database store using flat files for PHP.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors7

Languages


[8]ページ先頭

©2009-2025 Movatter.jp