Download the PHP package nerou/large-array-buffer without Composer

On this page you can find all versions of the php package nerou/large-array-buffer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package large-array-buffer

LargeArrayBuffer

License PHP Version Require Version Psalm Type Coverage

This is for you, if...

...you are working with pretty large arrays that conflict with close to every memory limit you can set. The array elements on the other hand should not be that big, such that you can keep a single element in memory quite easily. If the array gets too big for memory, it will be moved to disk temporarily and transparently. You can still iterate over it as if it was a normal array.

One typical use case would be to load a lot of datasets from a database at once. (There are reasons to prefer this over running multiple queries.) See Usage below for an example for this use case using this library.

Install

Note: This library requires PHP 8.0+!

Use composer to install this library:

composer require nerou/large-array-buffer

There are pretty much no dependencies with some exceptions:

Usage

Options

The constructor of LargeArrayBuffer provides some options:

  1. You can set the threshold when to move the data to disk. When pushing data to the buffer, it is stored in memory until it gets too large. E.g.: new LargeArrayBuffer(512); to set a 512 MiB threshold.
  2. You can choose either the PHP serializer, the igbinary serializer or the msgpack serializer (PHP serializer is default). E.g.: new LargeArrayBuffer(serializer: LargeArrayBuffer::COMPRESSION_IGBINARY);
  3. You can enable GZIP or LZ4 compression for the serialized items. Although this is recommended only if your items are pretty big like > 1 KiB each. E.g.: new LargeArrayBuffer(compression: LargeArrayBuffer::COMPRESSION_GZIP);. Note, that LZ4 compression requires ext-lz4 to be loaded.

Read from the buffer

There are several options to read the data:

  1. Iterate: As you might have seen in the example above, you can iterate over the buffer just like over an array with foreach. foreach($buffer as $item){ /* work with your data here */ }
  2. toArray(): If you have a set of buffers which do not fit in memory all together but one at a time, you can use $buffer->toArray() to get an array to work with.
  3. toJSONFile(): If you want to write the array in JSON format to some file or resource, use this method. It supports all the json_encode() options and flags.

Buffer stats

There are some stats you can obtain:

  1. count(): The number of items in the buffer.
  2. getSize(): The number of bytes of the serialized (!) data.

How it works

To put it in one sentence: This library uses php://temp as well as PHP's serialize/unserialize functions to store an array on disk if it gets too large.

Limitations and concerns

Benchmark

A benchmark with 1 million measurements (consisting of DateTimeImmutable, int and float) using PHP 8.1 with 10 iterations comparing a normal array with the LargeArrayBuffer gave the following results (LargeArrayBuffer was configured with a memory limit of 128 MiB):

Action Serializer Compression Consumed time Consumed memory Buffer size
Fill array none none 1.57 s 490.0 MiB NA
Iterate over array none none 0.27 s 492.0 MiB NA
Fill buffer PHP none 4.27 s 0 B 378.7 MiB
Iterate over buffer PHP none 2.85 s 0 B 378.7 MiB
Fill buffer PHP GZIP 24.76 s 0 B 192.5 MiB
Iterate over buffer PHP GZIP 6.79 s 0 B 192.5 MiB
Fill buffer PHP LZ4 4.89 s 0 B 241.0 MiB
Iterate over buffer PHP LZ4 2.93 s 0 B 241.0 MiB
Fill buffer igbinary none 4.26 s 0 B 319.1 MiB
Iterate over buffer igbinary none 3.41 s 0 B 319.1 MiB
Fill buffer igbinary GZIP 21.50 s 0 B 173.2 MiB
Iterate over buffer igbinary GZIP 4.80 s 0 B 173.2 MiB
Fill buffer igbinary LZ4 4.38 s 0 B 195.1 MiB
Iterate over buffer igbinary LZ4 3.17 s 0 B 195.1 MiB

Note:

To reproduce call bench/benchmark.php.

License

This library is licensed under the MIT License (MIT). Please see LICENSE for more information.


All versions of large-array-buffer with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package nerou/large-array-buffer contains the following files

Loading the files please wait ....