Giter Club home page Giter Club logo

flintstone's Introduction

Flintstone

Total Downloads Build Status

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

Features include:

  • Memory efficient
  • File locking
  • Caching
  • Gzip compression
  • Easy to use

For full documentation please visit http://www.xeweb.net/flintstone/

Installation

The easiest way to install Flintstone is via composer. Run the following command to install it.

php composer.phar require fire015/flintstone
<?php
require 'vendor/autoload.php';

use Flintstone\Flintstone;

$users = new Flintstone('users', array('dir' => '/path/to/database/dir/'));

Requirements

  • Any flavour of PHP 5.3+ should do
  • [optional] PHPUnit to execute the test suite

Data types

Flintstone can store the following data types:

  • Strings
  • Integers
  • Floats
  • Arrays

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

// Set options
$options = array('dir' => '/path/to/database/dir/');

// Load the databases
$users = new Flintstone('users', $options);
$settings = new Flintstone('settings', $options);

// Set keys
$users->set('bob', array('email' => '[email protected]', 'password' => '123456'));
$users->set('joe', array('email' => '[email protected]', 'password' => 'test'));
$settings->set('site_offline', 1);
$settings->set('site_back', '3 days');

// Retrieve keys
$user = $users->get('bob');
echo 'Bob, your email is ' . $user['email'];

$offline = $settings->get('site_offline');
if ($offline == 1) {
	echo 'Sorry, the website is offline<br />';
	echo 'We will be back in ' . $settings->get('site_back');
}

// Retrieve all key names
$keys = $users->getKeys(); // returns array('bob', 'joe', ...)

foreach ($keys as $username) {
	$user = $users->get($username);
	echo $username.', your email is ' . $user['email'];
	echo $username.', your password is ' . $user['password'];
}

// Delete a key
$users->delete('joe');

// 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
require 'vendor/autoload.php';

use Flintstone\Flintstone;
use Flintstone\Formatter\JsonFormatter;

$users = new Flintstone('users', array(
	'dir' => __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.

Who is using Flintstone?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.