PHPackages                             haveyb/export-csv - 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. [File &amp; Storage](/categories/file-storage)
4. /
5. haveyb/export-csv

ActiveLibrary[File &amp; Storage](/categories/file-storage)

haveyb/export-csv
=================

PHP 数据导出，使用 yield 优化导出大数据量时内存占用过高导致宕机

v2.0(6y ago)81741MITPHPPHP &gt;=7.1

Since Apr 12Pushed 6y ago1 watchersCompare

[ Source](https://github.com/haveyb/export-csv)[ Packagist](https://packagist.org/packages/haveyb/export-csv)[ RSS](/packages/haveyb-export-csv/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependenciesVersions (3)Used By (0)

1、说明

PHP 在大数据导出。尤其是上五十万以后，就会显得尤为吃内存，使用常规的导出方法，可能会导致内存溢出，直接整个服务都挂掉。

其实 PHP 从 5.5 开始，就已经有了迭代器 yield，使用 yield，可以大量的节省内存，不用再担心导出百万千万条数据，内存溢出了。

2、配置

配置MySQL连接参数，在 src/MySQLConfig.php 下

默认使用 default 下标下的配置参数连接，可以在调用时传递指定的连接

3、使用

```
$csv = new ExportCsv();

$sql = 'select admin_id,user_name,age from admin';

$head = ['用户ID', '用户名', '年龄'];

$csv->exportCsv($sql, $head, 'test_1', '后台用户表');
```

效果示例：

[![](src/example.png)](src/example.png)

注意：

在导出数据到表格时，第一个字段名尽量不要设置为 'ID' 这两个字母，因为这将会使 wps 报一个 ’wps表格已经监测到...是SYLK文件，但是不能将其加载‘的错误，不妨试一试。

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community8

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 ~0 days

Total

2

Last Release

2226d ago

Major Versions

v1.0 → v2.02020-04-12

### Community

Maintainers

![](https://www.gravatar.com/avatar/5e26307248e2784b57bfbc13f74768e7799f5fb30c209b4aa33e49b7a921e7b4?d=identicon)[haveyb](/maintainers/haveyb)

---

Top Contributors

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

---

Tags

yield

### Embed Badge

![Health badge](/badges/haveyb-export-csv/health.svg)

```
[![Health](https://phpackages.com/badges/haveyb-export-csv/health.svg)](https://phpackages.com/packages/haveyb-export-csv)
```

###  Alternatives

[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k39.8M123](/packages/knplabs-gaufrette)[google/cloud-storage

Cloud Storage Client for PHP

34390.8M125](/packages/google-cloud-storage)[illuminate/filesystem

The Illuminate Filesystem package.

15261.6M2.6k](/packages/illuminate-filesystem)[superbalist/flysystem-google-storage

Flysystem adapter for Google Cloud Storage

26320.6M30](/packages/superbalist-flysystem-google-storage)[creocoder/yii2-flysystem

The flysystem extension for the Yii framework

2931.7M62](/packages/creocoder-yii2-flysystem)[flowjs/flow-php-server

PHP library for handling chunk uploads. Works with flow.js html5 file uploads.

2451.6M15](/packages/flowjs-flow-php-server)

PHPackages © 2026

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