mateuszanella/php-ext-xz

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

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 0

Forks: 1

Open Issues: 2

Language:C

Type:php-ext

Ext name:ext-xz

pkg:composer/mateuszanella/php-ext-xz

v1.2.0 2025-09-26 11:14 UTC

This package is auto-updated.

Last update: 2025-10-26 11:29:09 UTC


README

PHP Extension providing XZ (LZMA2) compression/decompression functions.

Installation

The recommended way to install the extension is using pie:

pie install mateuszanella/php-ext-xz

This will download the source and compile the extension for your current PHP version. After installing the module, you may need to enable it in your php.ini file.

Configuration

php.ini

Add the following line to your php.ini configuration file:

extension=xz.so

You can also configure the default compression level and memory limit:

; Default compression level. Affects `xzencode` and `xzopen`, 
; but only when the level was not specified. 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

Build from Source

For detailed build and installation instructions from source, please see docs/BUILD.md.

Basic usage

String-based operations

You can easily compress and decompress strings.

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

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

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

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);

Credits

This repository is a fork from php-ext-xz by codemasher, originally forked from the RFC.

You can see the full list of contributors here.