PHPackages                             mehr-it/buffer - 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. mehr-it/buffer

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

mehr-it/buffer
==============

Library implementing buffer utilities

1.3.0(5y ago)15.8k3MITPHPPHP &gt;=7.0CI failing

Since Jul 22Pushed 5y agoCompare

[ Source](https://github.com/mehr-it/buffer)[ Packagist](https://packagist.org/packages/mehr-it/buffer)[ RSS](/packages/mehr-it-buffer/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (5)Used By (3)

Buffer utilities
================

[](#buffer-utilities)

This is a small library implementing simple buffer utilities for dealing with large data sets.

Flushing buffers
----------------

[](#flushing-buffers)

Flushing buffers implement buffers with a given size which are automatically flushed using a given handler function when they are full.

You may create an instance as follows. It Takes up to three arguments:

```
new FlushingBuffer(10, function(data) { /* send data */ });
new FlushingBuffer(10, function(data) { /* send data */ }, function() { return collect(); });

```

The first argument specifies the buffer size, the second one a handler function which is called each time the buffer is full. It receives the buffer data as argument. The third one is optional and acts as resolver for the underlying data structure to use. If omitted a simple array is used.

New items are added to the buffer using the `add()`-method. Usually you want the buffer to be flushed a last time, after all data was added, even if it's not full. To achieve this, simply call the `flush()`-method to manually flush the buffer:

```
$b = new FlushingBuffer(2, function(data) { /* send data */ });
$b->add(1);
$b->add(2);
$b->add(3);
$b->flush();

```

You may also specify a key, if you want to replace elements in the buffer at given key.

```
$b = new FlushingBuffer(2, function(data) { /* send data */ });
$b->add(1, 'key1');
$b->add(2, 'key1');

```

Of course replacing and existing element does not increase buffer size and therefore does not cause a buffer flush.

### Adding multiple items

[](#adding-multiple-items)

To add multiple items to the buffer at once, the `addMultiple()` method can be used. By default keys are not preserved. You can change this by passing `true` as second parameter.

```
$b = new FlushingBuffer(2, function(data) { /* send data */ });
$b->addMultiple([1, 2, 3]);

// with preserved keys

$b->addMultiple(['a' => 1, 'b' => 2, 'c' => 3], true);

```

### Filling array keys

[](#filling-array-keys)

To fill multiple keys with the same value, the `fillKeys()` method can be used:

```
$b = new FlushingBuffer(2, function(data) { /* send data */ });
$b->fillKeys(['a', 'b', 'c'], 1);

```

This will add/replace the keys `"a"`, `"b"` and `"c"` with the value `1`.

### Setting values by path

[](#setting-values-by-path)

The `setPath()` method sets a value for the given array path. The path can be specified as string using "dot notation" or as array:

```
$b = new FlushingBuffer(2, function(data) { /* send data */ });

$b->setPath(['this', 'is', 'a' 'path'], 1);

$b->setPath('this.is.another.path'], 2);

```

This creates new array levels as needed but only root level items affect the buffer count.

Chunk processors
----------------

[](#chunk-processors)

Chunk processors allow to process an `iterable` in chunks and return the processed items as generator. They act pretty much like PHP's `array_chunk()` function except they working with any kind of `iterable` and returning a generator. Thus they are predestined for processing large data sets.

You may use them like this:

```
$in = function() { /* input generator code */ };

$generator = (new ChunkProcessor($in, 500, function($chunk) {
	yield /* ... */
}))->consume();

```

To maintain the keys, the `keepKeys` argument may be set to true:

```
$generator = (new ChunkProcessor($in, 500, $processor, null, true))->consume();

```

Als static method exists, which creates the processor and calls `consume()` in one step:

```
$generator = ChunkProcessor::process($in, 500, $processor);

```

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

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

Total

4

Last Release

2032d ago

PHP version history (2 changes)1.0.0PHP ^7.0

1.3.0PHP &gt;=7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/44973729?v=4)[mehr.IT GmbH](/maintainers/mehr-it)[@mehr-it](https://github.com/mehr-it)

---

Tags

generatorBufferchunked

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mehr-it-buffer/health.svg)

```
[![Health](https://phpackages.com/badges/mehr-it-buffer/health.svg)](https://phpackages.com/packages/mehr-it-buffer)
```

###  Alternatives

[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k118.7M719](/packages/symfony-maker-bundle)[simplesoftwareio/simple-qrcode

Simple QrCode is a QR code generator made for Laravel.

2.9k30.5M113](/packages/simplesoftwareio-simple-qrcode)[nikic/iter

Iteration primitives using generators

1.1k6.4M55](/packages/nikic-iter)[jeroendesloovere/vcard

This VCard PHP class can generate a vCard with some data. When using an iOS device it will export as a .ics file because iOS devices don't support the default .vcf files.

5173.9M14](/packages/jeroendesloovere-vcard)[lambdish/phunctional

λ PHP functional library

3642.1M24](/packages/lambdish-phunctional)[riimu/kit-phpencoder

Highly customizable alternative to var\_export for PHP code generation

748.3M36](/packages/riimu-kit-phpencoder)

PHPackages © 2026

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