olivier-ls/binary-storage-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

olivier-ls/binary-storage-php

Composer 安装命令:

composer require olivier-ls/binary-storage-php

包简介

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

README 文档

README

License PHP

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?

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

composer require olivier-ls/binary-storage-php

🚀 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

Method Description Example
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

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

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

MIT

olivier-ls/binary-storage-php 适用场景与选型建议

olivier-ls/binary-storage-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 3, 最近一次更新时间为 2025 年 12 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「performance」 「cache」 「storage」 「binary」 「trie」 「indexing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 olivier-ls/binary-storage-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 olivier-ls/binary-storage-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 olivier-ls/binary-storage-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 29
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-12