PHP Extension providing XZ (LZMA2) compression/decompression functions.
The recommended way to install the extension is using pie:
pie install mateuszanella/php-ext-xzThis 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.
Add the following line to your php.ini configuration file:
extension=xz.soYou 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=65536For detailed build and installation instructions from source, please see docs/BUILD.md.
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);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);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.