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.0(3mo ago)15573[1 issues](https://github.com/codemasher/php-ext-xz/issues)PHP-3.01CCI passing

Since Sep 12Pushed 3mo 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 1mo ago

READMEChangelog (7)DependenciesVersions (4)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://github.com/codemasher/php-ext-xz/workflows/Linux/badge.svg)](https://github.com/codemasher/php-ext-xz/actions/workflows/linux.yml)[![Windows PHP8 build](https://github.com/codemasher/php-ext-xz/workflows/Windows/badge.svg)](https://github.com/codemasher/php-ext-xz/actions/workflows/windows.yml)

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.2.0-8.5-ts-vs17-x86_64` to your `php.ini` (whatever the filename may be, you may omit the leading "php\_" and the extension), se 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);

$rh = 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

40

—

FairBetter than 88% of packages

Maintenance79

Regular maintenance activity

Popularity21

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 76% 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 ~74 days

Total

3

Last Release

99d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ada3d048807a11e536645fb87da881170b18f34c0c61fa09e34807c5d79e0b89?d=identicon)[codemasher](/maintainers/codemasher)

---

Top Contributors

[![codemasher](https://avatars.githubusercontent.com/u/592497?v=4)](https://github.com/codemasher "codemasher (92 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)")[![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.

2751.4M5](/packages/rubix-tensor)[simple-updates/phpwhois

This package contains a Whois (RFC954) library for PHP. It allows a PHP program to create a Whois object, and obtain the output of a whois query with the Lookup function.

251.4k](/packages/simple-updates-phpwhois)

PHPackages © 2026

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