PHPackages                             sujun/big-file - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. sujun/big-file

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sujun/big-file
==============

bigFile,大文件处理。亿级文件分割、去重、排序

v1.0.0(8y ago)213MITPHPPHP &gt;=5.6.0

Since Aug 5Pushed 8y ago1 watchersCompare

[ Source](https://github.com/351699382/bitFile)[ Packagist](https://packagist.org/packages/sujun/big-file)[ RSS](/packages/sujun-big-file/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependenciesVersions (2)Used By (0)

bigFile,大文件处理
=============

[](#bigfile大文件处理)

[![Software license](https://camo.githubusercontent.com/3b83d6d1b3b377ba8f41c1e4ac197ad0dc056a760ec10c1f6484aa7b617fcc5a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f68656c6569313132672f7061796d656e742e737667)](LICENSE)[![Latest development](https://camo.githubusercontent.com/fbd0d64a834c65c0454f037d9012c00c63a4c836819b10a576b9273deac8923d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f7269766572736c65692f7061796d656e742e737667)](https://packagist.org/packages/sujun/big-file)

---

先前公司有个需求就是对发送数据去重，因为每次发送过来的数据文件都比较大，加上公司权限太多，申请流程麻烦，因此用PHP来实现这个需求。给过来的数据文件都是几百到千W这样（1核512M内存处理1kW手机账号分割并去重大概5分钟），跑的没问题，其实私下测试亿级别也没问题,慢点而已~︶~。工具实现了csv文件的处理，如果你需要处理其它文件格式的话只要实现"File/FileAbstract"接口就可以了。

---

bigFile是什么？
===========

[](#bigfile是什么)

bigFile是一个PHP写的文件处理工具类。

安装
--

[](#安装)

通过composer，这是推荐的方式，可以使用composer.json 声明依赖，或者直接运行下面的命令。

```
    composer require "sujun/big-file:v1.0.0"
```

放入composer.json文件中

```
    "require": {
        "sujun/big-file": "v1.0.0"
    }
```

然后运行

```
composer update

```

去重： 原理是根据需要去重的字段分割大文件。

```
use BigFile\ClearRepeating;

try {
    $param=[
        'filePath'=>'./123456.csv',             //处理文件
        'savePath'=>'./data/',                  //保存路径
        'saveFileName'=>'test.csv',             //保存文件名,可不写
        'isProcess'=>false,                      //设置是否采用多进程方式处理
        'processNum'=>4,                        //开启进程数（需要isProcess设置为true时有效）
        'isRemoveFirst'=>true,                  //剔除首行，有些文件第一行是说明
        'column'=>0,                            //需要去重的字段，数字。0表示第一列
        'isHash'=>true,
        'hashFunc'=>function ($param, $mod) {   //去重hash函数，param变量表示文件的每一行。(根据你业务来定义)
            return fmod(crc32($param[0]), $mod);//$param[0]来写，一般对应column参数使用
        }
    ];
    $obj = new ClearRepeating($param);
    $obj->execute();//执行任务
} catch (\Exception $e) {
    echo $e->getMessage();
    exit;
}

```

分割：

```
use BigFile\Spliting;

try {
    $param = [
        'filePath' => './123456.csv', //处理文件
        'savePath' => './data/', //保存路径
        'saveFileName' => 'test.csv', //保存文件名,可不写
        'isProcess' => false, //设置是否采用多进程方式处理
        'processNum' => 4, //开启进程数（需要isProcess设置为true时有效）
        'maxLine' => 100000, //分割后每个文件保存行数
        'isRemoveFirst' => true, //剔除首行，有些文件第一行是说明
        'column' => 0, //需要把指定字段分到同一文件时指定这个参数并设置hashFunc。
        'isHash' => false,
        'hashFunc' => function ($param, $mod) { //分割hash函数，param变量表示文件的每一行，(根据你业务来定义)
            return fmod($param[0], $mod); //$param[0]来写，一般对应column参数使用
        },
    ];
    $obj = new Spliting($param);
    $obj->execute(); //执行任务
} catch (\Exception $e) {
    echo $e->getMessage();
    exit;
}

```

排序： 目前使用归并算法,使用方式需要自定排序。跟PHP的自定义usort函数类似

```
use BigFile\Sorting;

try {
    $param=[
        'filePath'=>'./123456.csv',             //处理文件
        'savePath'=>'./data/',                  //保存路径
        'saveFileName'=>'test.csv',             //保存文件名,可不写
        'isProcess'=>false,                      //设置是否采用多进程方式处理
        'processNum'=>4,                        //开启进程数（需要isProcess设置为true时有效）
        'maxLine'=>100000,                      //分割后每个文件保存行数
        'isRemoveFirst'=>true,                  //剔除首行，有些文件第一行是说明
        'column'=>0,                            //需要把指定字段分到同一文件时指定这个参数并设置hashFunc。
        'isHash'=>false,
        'hashFunc'=>function ($param, $mod) {   //分割hash函数，param变量表示文件的每一行，(根据你业务来定义)
            return fmod($param[0], $mod);//$param[0]来写，一般对应column参数使用
        },
        'sortFunc'=>function ($a, $b) {
            if($a[1] == $b[1]) {
              return 0;
            }
            return ($a[1] < $b[1]) ? -1 : 1;
        }
    ];
    $obj = new Sorting($param);
    $obj->execute();//执行任务

} catch (\Exception $e) {
    echo $e->getMessage();
    exit;
}

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

3206d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d0c20eff6102f25a31d136b16530787049fdcd4ba99892fae879a91b07797559?d=identicon)[tianlanjusi](/maintainers/tianlanjusi)

---

Top Contributors

[![351699382](https://avatars.githubusercontent.com/u/4371564?v=4)](https://github.com/351699382 "351699382 (7 commits)")

---

Tags

bigfile

### Embed Badge

![Health badge](/badges/sujun-big-file/health.svg)

```
[![Health](https://phpackages.com/badges/sujun-big-file/health.svg)](https://phpackages.com/packages/sujun-big-file)
```

PHPackages © 2026

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