PHPackages                             olivier-ls/binary-storage-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. olivier-ls/binary-storage-php

ActiveLibrary[Caching](/categories/caching)

olivier-ls/binary-storage-php
=============================

A high-performance binary storage system for PHP, reducing disk overhead and I/O operations

0.1.0(5mo ago)22MITPHPPHP &gt;=8.0

Since Dec 12Pushed 3mo agoCompare

[ Source](https://github.com/olivier-ls/binary-storage-php)[ Packagist](https://packagist.org/packages/olivier-ls/binary-storage-php)[ RSS](/packages/olivier-ls-binary-storage-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

BinaryStorage
=============

[](#binarystorage)

[![License](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)[![PHP](https://camo.githubusercontent.com/efc33820eea622b7119e4e8f304c3622be923425eb8ee1d34c7b42dbe2c2e847/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e302532422d3737374242343f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://camo.githubusercontent.com/efc33820eea622b7119e4e8f304c3622be923425eb8ee1d34c7b42dbe2c2e847/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e302532422d3737374242343f6c6f676f3d706870266c6f676f436f6c6f723d7768697465)

BinaryStorage is a lightweight binary key/value store for PHP. It keeps all values inside a single data file and all keys inside a binary index, reducing filesystem overhead and allowing fast random-access lookups.

It is designed for projects that need simple, fast persistent storage without running Redis, SQLite, or a full database.

**BinaryStorage is a fast, lightweight, zero-dependency binary key/value store for PHP (one data file, one index file).**

✔️ Why use BinaryStorage?
-------------------------

[](#️-why-use-binarystorage)

BinaryStorage may be useful if you want:

- A simple file-based storage (no server to run, no extensions)
- Fast lookup by key
- Efficient prefix search (startsWith) and substring search (contains)
- Low disk usage (one data file + one index file)
- Automatic cleanup via file compaction
- The ability to store any PHP value (array, scalar, object → via serialize)

It is not a replacement for a database, but fits well for caches, catalogs, and read-heavy workloads.

📦 Installation
--------------

[](#-installation)

composer require olivier-ls/binary-storage-php

🚀 Basic Usage
-------------

[](#-basic-usage)

```
use OlivierLS\BinaryStorage\BinaryStorage;

$store = new BinaryStorage(__DIR__ . '/data');

// Open (or create) a storage
$store->open('products');

// Write values
$store->set('products', 'product_123', [
    'name'  => 'MacBook Pro',
    'price' => 2499.99,
    'stock' => 42
]);

$store->set('products', 'product_456', ['name' => 'iPhone']);
$store->set('products', 'product_789', ['name' => 'iPad']);

// Save index
$store->saveIndex('products');

// Read a value
$product = $store->get('products', 'product_123');

// Prefix search
$list = $store->startsWith('products', 'product_');

// Substring search
$list = $store->contains('products', ['pad']);

// Compact the data file (optional)
$stats = $store->compact('products');

// Stats
print_r($store->stats('products'));

// Close
$store->close('products');
```

📘 API Overview
--------------

[](#-api-overview)

MethodDescriptionExample**open(string $store)**Opens (or creates) a storage file. Must be called before reading/writing.`$store->open('products');`**close(string $store)**Closes a storage file.`$store->close('products');`**closeAll()**Closes all opened storage files.`$store->closeAll();`**set(string $store, string $key, mixed $value, ?int $ttl)**Stores a value for a key (serialized automatically).`$store->set('products', 'p123', $data, 3600);`**setMultiple(string $store, array $items)**Stores multiple values.`$store->setMultiple('products', ['key' => 'value', ...])`**saveIndex(string $store)**Persists the in-memory index to disk (important after many writes).`$store->saveIndex('products');`**get(string $store, string $key)**Retrieves a value by key. Returns `null` if the key doesn't exist.`$product = $store->get('products', 'p123');`**getAllKeys(string $store)**Returns all keys.`$keys = $store->getAllKeys('products');`**delete(string $store, string $key)**Deletes a value by key.`$store->delete('products', 'p123');`**exists(string $store, string $key)**Checks whether a key exists.`if ($store->exists('products', 'p123')) { ... }`**startsWith(string $store, string $prefix)**Returns all values where the key starts with a prefix.`$list = $store->startsWith('products', 'p1');`**contains(string $store, array $patterns)**Returns all values where the key contains one or more substrings.`$list = $store->contains('products', ['12']);`**stats(string $store)**Returns file statistics (sizes, fragmentation, counts).`$info = $store->stats('products');`**compact(string $store)**Rebuilds the file and removes fragmentation.`$saved = $store->compact('products');`**deleteCache(string $store)**Deletes both the data and index files for a store.`$store->deleteCache('products');`- `$ttl` (optional) – Time-to-live in seconds. If provided, the entry will expire automatically after this time.

🧰 When to use it
----------------

[](#-when-to-use-it)

Good scenarios:

- Large product lists or catalog caching
- Simple local persistent storage
- High-volume read access
- CLI tools needing a lightweight storage
- Storing precomputed data
- Replacing many small JSON files

Less good scenarios:

- Heavy concurrent writes
- Complex queries
- Replacing a real database

🤝 Contributing
--------------

[](#-contributing)

Issues and pull requests are welcome. If you find a performance bottleneck or have an idea for improved index structures, feel free to open a discussion.

📄 License
---------

[](#-license)

MIT

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance76

Regular maintenance activity

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity29

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

157d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/432f52698b9fa66ae79ce47aedb7354805905e8fa15053b1d2f3d8480b15f9dd?d=identicon)[olivier-ls](/maintainers/olivier-ls)

---

Top Contributors

[![olivier-ls](https://avatars.githubusercontent.com/u/247223033?v=4)](https://github.com/olivier-ls "olivier-ls (23 commits)")

---

Tags

binary-storagecachekey-value-storeperformancephpphp-librarystorageperformancecachestoragebinaryindexingtrie

### Embed Badge

![Health badge](/badges/olivier-ls-binary-storage-php/health.svg)

```
[![Health](https://phpackages.com/badges/olivier-ls-binary-storage-php/health.svg)](https://phpackages.com/packages/olivier-ls-binary-storage-php)
```

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.2M51](/packages/spatie-laravel-responsecache)[putyourlightson/craft-blitz

Intelligent static page caching for creating lightning-fast sites.

153471.5k29](/packages/putyourlightson-craft-blitz)[alekseykorzun/memcached-wrapper-php

Optimized PHP 5 wrapper for Memcached extension that supports dog-piling, igbinary and local storage

2984.6k1](/packages/alekseykorzun-memcached-wrapper-php)[anahkiasen/flatten

A package for the Illuminate framework that flattens pages to plain HTML

33113.0k](/packages/anahkiasen-flatten)[rarst/fragment-cache

WordPress plugin for partial and async caching of heavy front-end elements.

14115.0k2](/packages/rarst-fragment-cache)[silverstripe/staticpublishqueue

Static publishing queue to create static versions of pages for enhanced performance and security

45135.4k4](/packages/silverstripe-staticpublishqueue)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
