PHPackages                             kjdev/zstd - 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. kjdev/zstd

ActivePhp-ext[Utility &amp; Helpers](/categories/utility)

kjdev/zstd
==========

A compression/decompression with Zstandard

0.15.2(8mo ago)228824↑433.3%29[15 issues](https://github.com/kjdev/php-ext-zstd/issues)MITCPHP &gt;= 7.0.0CI passing

Since Apr 10Pushed 5mo ago10 watchersCompare

[ Source](https://github.com/kjdev/php-ext-zstd)[ Packagist](https://packagist.org/packages/kjdev/zstd)[ RSS](/packages/kjdev-zstd/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)DependenciesVersions (5)Used By (0)

Zstd Extension for PHP
======================

[](#zstd-extension-for-php)

[![Linux](https://github.com/kjdev/php-ext-zstd/actions/workflows/linux.yaml/badge.svg?branch=master)](https://github.com/kjdev/php-ext-zstd/actions/workflows/linux.yaml)[![Windows](https://github.com/kjdev/php-ext-zstd/actions/workflows/windows.yaml/badge.svg?branch=master)](https://github.com/kjdev/php-ext-zstd/actions/workflows/windows.yaml)

This extension allows Zstandard.

Documentation for Zstandard can be found at [» https://github.com/facebook/zstd](https://github.com/facebook/zstd).

Build from sources
------------------

[](#build-from-sources)

```
% git clone --recursive --depth=1 https://github.com/kjdev/php-ext-zstd.git
% cd php-ext-zstd
% phpize
% ./configure
% make
% make install
```

To use the system library

```
% ./configure --with-libzstd
```

> minimum system libzstd library version to 1.4.0

Install from [pecl](https://pecl.php.net/package/zstd):

```
% pecl install zstd
```

Distribution binary packages
----------------------------

[](#distribution-binary-packages)

### Fedora

[](#fedora)

Fedora users can install the [» php-zstd](https://packages.fedoraproject.org/pkgs/php-zstd/php-zstd/) package from official repository.

```
dnf install php-zstd
```

### CentOS / RHEL

[](#centos--rhel)

CentOS / RHEL (and other clones) users can install the [» php-zstd](https://packages.fedoraproject.org/pkgs/php-zstd/php-zstd/) package from [» EPEL](https://fedoraproject.org/wiki/EPEL) repository.

```
yum install php-zstd
```

Other RPM packages of this extension, for other PHP versions, are available in [» Remi's RPM repository](https://rpms.remirepo.net/).

Configration
------------

[](#configration)

php.ini:

```
extension=zstd.so

```

### Output handler option

[](#output-handler-option)

NameDefaultChangeablezstd.output\_compression0PHP\_INI\_ALLzstd.output\_compression\_level3PHP\_INI\_ALLzstd.output\_compression\_dict""PHP\_INI\_ALL- zstd.output\_compression *boolean*/*integer*

    Whether to transparently compress pages. If this option is set to "On" in php.ini or the Apache configuration, pages are compressed if the browser sends an "Accept-Encoding: zstd" header. "Content-Encoding: zstd" and "Vary: Accept-Encoding" headers are added to the output. In runtime, it can be set only before sending any output.
- zstd.output\_compression\_level *integer*

    Compression level used for transparent output compression. Specify a value between 1 to 22. The default value of `ZSTD_COMPRESS_LEVEL_DEFAULT` (3).
- zstd.output\_compression\_dict *string*

    Specifies the path to the compressed dictionary file to be used by the output handler.

Constant
--------

[](#constant)

NameDescriptionZSTD\_COMPRESS\_LEVEL\_MINMinimal compress level valueZSTD\_COMPRESS\_LEVEL\_MAXMaximal compress level valueZSTD\_COMPRESS\_LEVEL\_DEFAULTDefault compress level valueZSTD\_VERSION\_NUMBERlibzstd version numberZSTD\_VERSION\_TEXTlibzstd version stringFunction
--------

[](#function)

- zstd\_compress — Zstandard compression
- zstd\_uncompress — Zstandard decompression
- zstd\_compress\_dict — Zstandard compression using a digested dictionary
- zstd\_uncompress\_dict — Zstandard decompression using a digested dictionary
- zstd\_compress\_init — Initialize an incremental compress context
- zstd\_compress\_add — Incrementally compress data
- zstd\_uncompress\_init — Initialize an incremental uncompress context
- zstd\_uncompress\_add — Incrementally uncompress data

---

### zstd\_compress — Zstandard compression

[](#zstd_compress--zstandard-compression)

#### Description

[](#description)

```
zstd_compress ( string $data, int $level = ZSTD_COMPRESS_LEVEL_DEFAULT, ?string $dict = null ): string|false
```

Zstandard compression.

#### Parameters

[](#parameters)

- *data*

    The string to compress.
- *level*

    The level of compression (e.g. 1-22). (Defaults to `ZSTD_COMPRESS_LEVEL_DEFAULT`)

    A value smaller than 0 means a faster compression level. (Zstandard library 1.3.4 or later)
- *dict*

    The Dictionary data.

#### Return Values

[](#return-values)

Returns the compressed data or FALSE if an error occurred.

---

### zstd\_uncompress — Zstandard decompression

[](#zstd_uncompress--zstandard-decompression)

#### Description

[](#description-1)

```
zstd_uncompress ( string $data, ?string $dict = null ): string|false
```

Zstandard decompression.

> Alias: zstd\_decompress

#### Parameters

[](#parameters-1)

- *data*

    The compressed string.
- *dict*

    The Dictionary data.

#### Return Values

[](#return-values-1)

Returns the decompressed data or FALSE if an error occurred.

---

### zstd\_compress\_dict — Zstandard compression using a digested dictionary

[](#zstd_compress_dict--zstandard-compression-using-a-digested-dictionary)

> deprecated: use zstd\_compress() insted

#### Description

[](#description-2)

```
zstd_compress_dict ( string $data , string $dict, int $level = ZSTD_COMPRESS_LEVEL_DEFAULT ): string|false
```

Zstandard compression using a digested dictionary.

> Alias: zstd\_compress\_usingcdict

#### Parameters

[](#parameters-2)

- *data*

    The string to compress.
- *dict*

    The Dictionary data.
- *level*

    The level of compression (e.g. 1-22). (Defaults to `ZSTD_COMPRESS_LEVEL_DEFAULT`)

#### Return Values

[](#return-values-2)

Returns the compressed data or FALSE if an error occurred.

---

### zstd\_uncompress\_dict — Zstandard decompression using a digested dictionary

[](#zstd_uncompress_dict--zstandard-decompression-using-a-digested-dictionary)

> deprecated: use zstd\_uncompress() insted

#### Description

[](#description-3)

```
zstd_uncompress_dict ( string $data , string $dict ): string|false
```

Zstandard decompression using a digested dictionary.

> Alias: zstd\_decompress\_dict, zstd\_uncompress\_usingcdict, zstd\_decompress\_usingcdict

#### Parameters

[](#parameters-3)

- *data*

    The compressed string.
- *dict*

    The Dictionary data.

#### Return Values

[](#return-values-3)

Returns the decompressed data or FALSE if an error occurred.

---

### zstd\_compress\_init — Initialize an incremental compress context

[](#zstd_compress_init--initialize-an-incremental-compress-context)

#### Description

[](#description-4)

```
zstd_compress_init ( int $level = ZSTD_COMPRESS_LEVEL_DEFAULT, ?string $dict = null ): Zstd\Compress\Context|false
```

Initialize an incremental compress context

#### Parameters

[](#parameters-4)

- *level*

    The higher the level, the slower the compression. (Defaults to `ZSTD_COMPRESS_LEVEL_DEFAULT`)
- *dict*

    The Dictionary data.

#### Return Values

[](#return-values-4)

Returns a zstd context instance on success, or FALSE on failure

---

### zstd\_compress\_add — Incrementally compress data

[](#zstd_compress_add--incrementally-compress-data)

#### Description

[](#description-5)

```
zstd_compress_add ( Zstd\Compress\Context $context, string $data, bool $end = false ): string|false
```

Incrementally compress data

#### Parameters

[](#parameters-5)

- *context*

    A context created with `zstd_compress_init()`.
- *data*

    A chunk of data to compress.
- *end*

    Set to true to terminate with the last chunk of data.

#### Return Values

[](#return-values-5)

Returns a chunk of compressed data, or FALSE on failure.

---

### zstd\_uncompress\_init — Initialize an incremental uncompress context

[](#zstd_uncompress_init--initialize-an-incremental-uncompress-context)

#### Description

[](#description-6)

```
zstd_uncompress_init ( ?string $dict = null ): Zstd\UnCompress\Context|false
```

Initialize an incremental uncompress context

#### Parameters

[](#parameters-6)

- *dict*

    The Dictionary data.

#### Return Values

[](#return-values-6)

Returns a zstd context instance on success, or FALSE on failure

---

### zstd\_uncompress\_add — Incrementally uncompress data

[](#zstd_uncompress_add--incrementally-uncompress-data)

#### Description

[](#description-7)

```
zstd_uncompress_add ( Zstd\UnCompress\Context $context, string $data ): string|false
```

Incrementally uncompress data

#### Parameters

[](#parameters-7)

- *context*

    A context created with `zstd_uncompress_init()`.
- *data*

    A chunk of compressed data.

#### Return Values

[](#return-values-7)

Returns a chunk of uncompressed data, or FALSE on failure.

Namespace
---------

[](#namespace)

```
Namespace Zstd;

function compress( string $data, int $level = ZSTD_COMPRESS_LEVEL_DEFAULT ): string|false {}
function uncompress( string $data ): string|false {}
function compress_dict ( string $data, string $dict, int $level = ZSTD_COMPRESS_LEVEL_DEFAULT ): string|false {}
function uncompress_dict ( string $data, string $dict ): string|false {}
function compress_init ( int $level = ZSTD_COMPRESS_LEVEL_DEFAULT ): \Zstd\Compress\Context|false {}
function compress_add ( \Zstd\Compress\Context $context, string $data, bool $end = false ): string|false {}
function uncompress_init (): \Zstd\UnCompress\Context|false {}
function uncompress_add ( \Zstd\UnCompress\Context $context, string $data ): string|false
```

`zstd_compress`, `zstd_uncompress`, `zstd_compress_dict`, `zstd_uncompress_dict`, `zstd_compress_init`, `zstd_compress_add`, `zstd_uncompress_init` and `zstd_uncompress_add` function aliases.

Streams
-------

[](#streams)

Zstd compression and decompression are available using the `compress.zstd://` stream prefix.

Output handler
--------------

[](#output-handler)

```
ini_set('zstd.output_compression', 'On');
// OR
// ob_start('ob_zstd_handler');

echo ...;
```

> "Accept-Encoding: zstd" must be specified.

> Experimental: [Compression Dictionary Transport](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Compression_dictionary_transport) support
>
> must be specified headers.
>
> - `Accept-Encoding: dcz`
> - `Available-Dictionary: ::`

Examples
--------

[](#examples)

```
// Using functions
$data = zstd_compress('test');
zstd_uncompress($data);

// Using namespaced functions
$data = \Zstd\compress('test');
\Zstd\uncompress($data);

// Using streams
file_put_contents("compress.zstd:///path/to/data.zstd", $data);
readfile("compress.zstd:///path/to/data.zstd");

// Providing level of compression, when using streams
$context = stream_context_create([
    'zstd' => [
            'level' => ZSTD_COMPRESS_LEVEL_MIN,
            // 'dict' => $dict,
        ],
    ],
);

file_put_contents("compress.zstd:///path/to/data.zstd", $data, context: $context);
readfile("compress.zstd:///path/to/data.zstd", context: $context);
```

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance64

Regular maintenance activity

Popularity38

Limited adoption so far

Community26

Small or concentrated contributor base

Maturity25

Early-stage or recently created project

 Bus Factor1

Top contributor holds 78.1% 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 ~48 days

Total

4

Last Release

259d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/18072f3d3a57cc6f8e11a0f405648caf4927261c0fc122f9cfa0d1441e087fb7?d=identicon)[kjdev](/maintainers/kjdev)

---

Top Contributors

[![kjdev](https://avatars.githubusercontent.com/u/465132?v=4)](https://github.com/kjdev "kjdev (250 commits)")[![remicollet](https://avatars.githubusercontent.com/u/270445?v=4)](https://github.com/remicollet "remicollet (27 commits)")[![JakubOnderka](https://avatars.githubusercontent.com/u/163343?v=4)](https://github.com/JakubOnderka "JakubOnderka (16 commits)")[![sergey-dryabzhinsky](https://avatars.githubusercontent.com/u/717597?v=4)](https://github.com/sergey-dryabzhinsky "sergey-dryabzhinsky (7 commits)")[![thekid](https://avatars.githubusercontent.com/u/696742?v=4)](https://github.com/thekid "thekid (4 commits)")[![glensc](https://avatars.githubusercontent.com/u/199095?v=4)](https://github.com/glensc "glensc (4 commits)")[![cmb69](https://avatars.githubusercontent.com/u/2306138?v=4)](https://github.com/cmb69 "cmb69 (3 commits)")[![dixyes](https://avatars.githubusercontent.com/u/11804369?v=4)](https://github.com/dixyes "dixyes (2 commits)")[![martinml](https://avatars.githubusercontent.com/u/217925?v=4)](https://github.com/martinml "martinml (1 commits)")[![nobuf](https://avatars.githubusercontent.com/u/211832?v=4)](https://github.com/nobuf "nobuf (1 commits)")[![dariuskasiulevicius](https://avatars.githubusercontent.com/u/1218606?v=4)](https://github.com/dariuskasiulevicius "dariuskasiulevicius (1 commits)")[![romulasry](https://avatars.githubusercontent.com/u/19944656?v=4)](https://github.com/romulasry "romulasry (1 commits)")[![berezuev](https://avatars.githubusercontent.com/u/695546?v=4)](https://github.com/berezuev "berezuev (1 commits)")[![fedotov-as](https://avatars.githubusercontent.com/u/7966803?v=4)](https://github.com/fedotov-as "fedotov-as (1 commits)")[![DemOnJR](https://avatars.githubusercontent.com/u/6385558?v=4)](https://github.com/DemOnJR "DemOnJR (1 commits)")

### Embed Badge

![Health badge](/badges/kjdev-zstd/health.svg)

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

###  Alternatives

[dsposito/argo

A shipping utility.

23177.0k](/packages/dsposito-argo)

PHPackages © 2026

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