PHPackages                             codemasher/php-ext-xz - 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. codemasher/php-ext-xz

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

codemasher/php-ext-xz
=====================

A PHP Extension providing xz (LZMA2) compression/decompression via PHP streams.

1.2.1(2mo ago)171154[2 issues](https://github.com/codemasher/php-ext-xz/issues)PHP-3.01CCI passing

Since Sep 12Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/codemasher/php-ext-xz)[ Packagist](https://packagist.org/packages/codemasher/php-ext-xz)[ Docs](https://github.com/codemasher/php-ext-xz)[ Fund](https://ko-fi.com/codemasher)[ RSS](/packages/codemasher-php-ext-xz/feed)WikiDiscussions main Synced today

READMEChangelog (8)DependenciesVersions (6)Used By (0)

php-ext-xz
==========

[](#php-ext-xz)

PHP Extension providing XZ (LZMA2) compression/decompression functions (see [Implement lzma (xz?) compression](https://news-web.php.net/php.internals/106654)).

[![Linux build](https://camo.githubusercontent.com/e4d650d5fe6e66dfd18f72888b2cbf6d64909f70a1d495717aaa56194726ffb3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636f64656d61736865722f7068702d6578742d787a2f6c696e75782e796d6c3f6272616e63683d6d61696e266c6f676f3d676974687562266c6f676f436f6c6f723d636363266c6162656c3d4c696e75782532306275696c64)](https://github.com/codemasher/php-ext-xz/actions/workflows/linux.yml?query=branch%3Amain)[![Windows build](https://camo.githubusercontent.com/31ec320919f103d9abf22e0d067c0ae511b36fa683277e61ad0c424ffebb95f5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636f64656d61736865722f7068702d6578742d787a2f77696e646f77732e796d6c3f6272616e63683d6d61696e266c6f676f3d676974687562266c6f676f436f6c6f723d636363266c6162656c3d57696e646f77732532306275696c64)](https://github.com/codemasher/php-ext-xz/actions/workflows/windows.yml?query=branch%3Amain)[![Packagist version](https://camo.githubusercontent.com/ecdc6cb42b2ad045cac7129b568865f1f589a0185291b0c8bc274dca8c84df0a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f64656d61736865722f7068702d6578742d787a2e7376673f6c6f676f3d7061636b6167697374266c6f676f436f6c6f723d636363)](https://packagist.org/packages/codemasher/php-ext-xz)

Installation
------------

[](#installation)

The recommended way to install [the extension](https://packagist.org/packages/codemasher/php-ext-xz) is using [PIE](https://github.com/php/pie):

```
pie install codemasher/php-ext-xz
```

Windows builds are now done automatically; you can download them from the [releases](https://github.com/codemasher/php-ext-xz/releases). Copy the dll file into the `/ext` directory of your PHP installation and add the line `extension=xz-1.x.x-8.5-ts-vs17-x86_64` to your `php.ini` (whatever the filename may be, you may omit the leading "php\_" and the extension), see also: [Loading an extension](https://www.php.net/manual/en/install.pecl.windows.php#install.pecl.windows.loading) in the PHP manual.

You can check if the extension is loaded via `phpinfo()`, or from within PHP via:

```
if(!extension_loaded('xz')){
	throw new Exception('ext-xz not loaded!');
}

// ...continue to do stuff with ext-xz...
```

Basic usage
-----------

[](#basic-usage)

### String-based operations

[](#string-based-operations)

You can easily compress and decompress strings.

```
$string = 'This is a test string that will be compressed and then decompressed.';

// Compress a string
$compressed = xzencode($string);

// Decompress a string
$decompressed = xzdecode($compressed);
```

### File-based operations

[](#file-based-operations)

The extension also supports stream-based operations for working with `.xz` files.

```
$file = '/tmp/test.xz';

// Writing to an .xz file
$wh = xzopen($file, 'w');
xzwrite($wh, 'Data to write');
xzclose($wh);

// Reading from an .xz file and outputting its contents
$rh = xzopen($file, 'r');
xzpassthru($rh);
xzclose($rh);
```

Configuration
-------------

[](#configuration)

You can configure the default compression level and memory limit:

```
; Default compression level. Affects `xzencode` and `xzopen`,
; but only when the level was not specified. Values 0-9, default is 5.
xz.compression_level=5

; The maximum amount of memory that can be used when decompressing. Default is 0 (no limit).
xz.max_memory=65536
```

Alternatively, the compression level can be supplied as a parameter to the `xzencode()` and `xzopen()` functions:

```
const COMPRESSION_LEVEL = 7;

$compressed = xzencode($string, COMPRESSION_LEVEL);

$wh = xzopen($file, 'w', COMPRESSION_LEVEL);
```

Build from source
-----------------

[](#build-from-source)

### Linux

[](#linux)

This module requires [`liblzma-dev`](https://packages.ubuntu.com/search?lang=de&keywords=liblzma-dev&searchon=names) () as well as php7-dev or php8-dev. If you are using Ubuntu, you can easily install all of them by typing the following command in your terminal:

```
sudo apt-get install git php7.4-dev liblzma-dev
```

To build and install as module, perform the following steps:

```
git clone https://github.com/codemasher/php-ext-xz.git
cd php-ext-xz
phpize
./configure
make
sudo make install
```

Do not forget to add `extension=xz.so` to your `php.ini`.

### Windows

[](#windows)

If you want to build it on your own, follow the steps under "[Build your own PHP on Windows](https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2)" to setup your build environment. Before the compilation step, clone this repository to `[...]\php-src\ext\xz` and proceed.

```
git clone https://github.com/Microsoft/php-sdk-binary-tools.git c:\php-sdk
cd c:\php-sdk
phpsdk-vs16-x64.bat
```

Run the buildtree script and check out the php source:

```
phpsdk_buildtree php-8.0
git clone https://github.com/php/php-src.git
cd php-src
git checkout PHP-8.0
```

Clone the xz extension and run the build:

```
git clone https://github.com/codemasher/php-ext-xz .\ext\xz
phpsdk_deps -u
buildconf --force
configure --enable-xz
nmake snap
```

Please note that the `liblzma` dependency is not included with PHP &lt; 8, so you will need to [download it manually](https://windows.php.net/downloads/php-sdk/deps/vs16/x64/liblzma-5.2.5-vs16-x64.zip) and extract it into the `deps` directory.

Disclaimer
----------

[](#disclaimer)

May or may not contain bugs. Use at your own risk.

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance83

Actively maintained with recent releases

Popularity22

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 76.9% 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 ~69 days

Total

4

Last Release

84d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/592497?v=4)[smiley](/maintainers/codemasher)[@codemasher](https://github.com/codemasher)

---

Top Contributors

[![codemasher](https://avatars.githubusercontent.com/u/592497?v=4)](https://github.com/codemasher "codemasher (100 commits)")[![udan11](https://avatars.githubusercontent.com/u/4147664?v=4)](https://github.com/udan11 "udan11 (13 commits)")[![remicollet](https://avatars.githubusercontent.com/u/270445?v=4)](https://github.com/remicollet "remicollet (11 commits)")[![nbianca](https://avatars.githubusercontent.com/u/23153890?v=4)](https://github.com/nbianca "nbianca (2 commits)")[![shivammathur](https://avatars.githubusercontent.com/u/1571086?v=4)](https://github.com/shivammathur "shivammathur (2 commits)")[![crazywhalecc](https://avatars.githubusercontent.com/u/20330940?v=4)](https://github.com/crazywhalecc "crazywhalecc (1 commits)")[![chobie](https://avatars.githubusercontent.com/u/195038?v=4)](https://github.com/chobie "chobie (1 commits)")

---

Tags

clzma2peclphpphp-extensionphp-streamphp5-is-deadphp7php8xzphp-extensionlzma2xz

### Embed Badge

![Health badge](/badges/codemasher-php-ext-xz/health.svg)

```
[![Health](https://phpackages.com/badges/codemasher-php-ext-xz/health.svg)](https://phpackages.com/packages/codemasher-php-ext-xz)
```

###  Alternatives

[rubix/tensor

A library and extension that provides objects for scientific computing in PHP.

2801.6M5](/packages/rubix-tensor)

PHPackages © 2026

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