PHPackages                             limen/fileflake - 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. [Database &amp; ORM](/categories/database)
4. /
5. limen/fileflake

ActiveLibrary[Database &amp; ORM](/categories/database)

limen/fileflake
===============

A distributed file server utilizes mongodb as the storage backend.

v0.2.3(9y ago)631MITPHPPHP &gt;=5.5.9

Since Dec 8Pushed 9y agoCompare

[ Source](https://github.com/limen/fileflake)[ Packagist](https://packagist.org/packages/limen/fileflake)[ Docs](https://github.com/limen/fileflake)[ RSS](/packages/limen-fileflake/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (5)Dependencies (5)Versions (6)Used By (0)

Fileflake
=========

[](#fileflake)

A distributed file server utilizes mongodb(not mongo GridFS) as the storage backend for Larevel.

[![Build Status](https://camo.githubusercontent.com/f668926d8b0316d4ebed0897956e5d69ac1156b32c3af97a2c0cbc1df42cabe2/68747470733a2f2f7472617669732d63692e6f72672f6c696d656e2f66696c65666c616b652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/limen/fileflake)[![Packagist](https://camo.githubusercontent.com/a02eceae694a94f99891ad3cd38f673d030baa5f92dd8e299769e95a0fc62e26/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c696d656e2f66696c65666c616b652e7376673f6d61784167653d32353932303030)](https://packagist.org/packages/limen/fileflake)

Features
--------

[](#features)

- supported operations: upload, download, delete
- distributed storage nodes
- storage nodes load balance
- easy to scale out (add more storage nodes on the fly)
- file stream stored in mongodb
- file stream is divided into chunks and the chunk size is configurable
- file chunks could be iterated without making a local copy
- files have same checksum would only store one copy

Getting start
-------------

[](#getting-start)

### Installation

[](#installation)

Recommend to install via [composer](https://getcomposer.org/).

```
composer require "limen/fileflake"
```

### Usage

[](#usage)

```
use Limen\Fileflake\Config;

$config = [
    Config::KEY_FILE_META_CONNECTION => 'mongodb',          // required, file meta connection
    Config::KEY_FILE_META_COLLECTION => 'FileMeta',         // required, file meta collection
    Config::KEY_NODE_META_CONNECTION => 'mongodb',          // required, node meta connection
    Config::KEY_NODE_META_COLLECTION => 'NodeMeta',         // required, node meta collection

    Config::KEY_FILE_CHUNK_SIZE     => 51200,               // required, chunk size in byte

    // if set to true, the load balance would consider file count and file volume of each storage node,
    // or the load balance would pick one node randomly
    Config::KEY_LOAD_BALANCE_STRICT => true,                // optional, default value is false

    // required
    Config::KEY_FILE_CONTENT_STORAGE_NODES => [
        [
            'id'         => 1,                              // storage node id, should be unique and unmodifiable
            'connection' => 'mongodb',                      // storage node connection
            'collection' => 'FileStorage1',                 // storage node collection
        ],
        [
            'id'         => 2,
            'connection' => 'mongodb',
            'collection' => 'FileStorage2',
        ],
    ],

    Config::KEY_LOCALIZE_DIR     => '/tmp/fileflake/localize',      // required, the temp local files stored in this directory

    // optional, see default values below
    Config::KEY_CONTRACT_CONCRETE_MAP => [
        \Limen\Fileflake\Contracts\UidGeneratorContract::class => \Limen\Fileflake\Support\UidGenerator::class,
        \Limen\Fileflake\Contracts\BalancerContract::class => \Limen\Fileflake\LoadBalancer::class,
        \Limen\Fileflake\Contracts\LockContract::class => \Limen\Fileflake\Lock\RedLock::class,
        \Limen\Fileflake\Contracts\FileContainerContract::class => \Limen\Fileflake\FileContainer::class,
        \Limen\Fileflake\Contracts\FileMetaContract::class => \Limen\Fileflake\Storage\FileMetaStorage::class,
    ],
];

$filePath = '/path/to/file';
$file = new \Limen\Fileflake\Protocols\InputFile($filePath, 'fileflake.png', filesize($filePath), 'png', 'image/png');
$fileflake = new \Limen\Fileflake\Fileflake($config);

/** @var string $fileId md5 */
$fileId = $fileflake->put($file);

/** @var \Limen\Fileflake\Protocols\OutputFile only file meta data */
$fileMeta = $fileflake->getMeta($fileId);

/** @var \Limen\Fileflake\Protocols\OutputFile  */
$localFile = $fileflake->get($fileId);

$localFile->localize();     // make a local copy

/** @var string $localPath path of local copy */
$localPath = $localFile->path;

while ($chunk = $localFile->nextChunk()) {      // iterate file chunks without making a local copy
    // do something
}

// remove file
$fileflake->remove($fileId);

$fileflake->get($fileId);           // return null
```

System diagram
--------------

[](#system-diagram)

[![fileflake](https://github.com/limen/resources/raw/master/fileflake.png)](https://github.com/limen/resources/blob/master/fileflake.png)

Concepts
--------

[](#concepts)

### File meta

[](#file-meta)

Every file has a meta record.

The reference is similar to soft link in Linux file system.

A file is "source file" when it doesn't have a reference. On the contrary, the files which have reference are "soft links".

File's reference count (default 1) shows how many file(s) (including itself) are referring to it.

The system would only store the first one of the files which have same checksum and the others' references point to the first file.

When a soft link file is removed, its meta data would be deleted and the reference count of its source file would decrement by 1.

When a source file is removed, its reference count would decrement by 1.

When a source file's reference count decrement to 0, its meta data would be deleted and its chunks would be deleted from storage node.

#### meta fields

[](#meta-fields)

- file id
- file name
- file checksum
- file reference count
- file reference
- store node id
- chunk ids
- extension
- mime type

### Storage node

[](#storage-node)

The nodes store source file's chunks.

#### fields

[](#fields)

- chunk id
- chunk content

### Node meta

[](#node-meta)

Store the nodes meta data that would be used to load balance

#### fields

[](#fields-1)

- node id
- file count
- file volume

License
-------

[](#license)

MIT

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 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

Every ~29 days

Total

5

Last Release

3375d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3460683?v=4)[Mengxiang Li](/maintainers/limen)[@limen](https://github.com/limen)

---

Top Contributors

[![limen](https://avatars.githubusercontent.com/u/3460683?v=4)](https://github.com/limen "limen (11 commits)")

---

Tags

laravelserverfilemongodb

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/limen-fileflake/health.svg)

```
[![Health](https://phpackages.com/badges/limen-fileflake/health.svg)](https://phpackages.com/packages/limen-fileflake)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.4M94](/packages/mongodb-laravel-mongodb)[leroy-merlin-br/mongolid

Easy, powerful and ultrafast ODM for PHP and MongoDB.

11335.7k6](/packages/leroy-merlin-br-mongolid)

PHPackages © 2026

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