codemasher/php-ext-xz 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

codemasher/php-ext-xz

Composer 安装命令:

pie install codemasher/php-ext-xz

包简介

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

README 文档

README

PHP Extension providing XZ (LZMA2) compression/decompression functions (see Implement lzma (xz?) compression).

Linux build Windows build Packagist version

Installation

The recommended way to install the extension is using PIE:

pie install codemasher/php-ext-xz

Windows builds are now done automatically; you can download them from the 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 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

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

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

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

Linux

This module requires liblzma-dev (https://tukaani.org/xz/) 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

If you want to build it on your own, follow the steps under "Build your own PHP on Windows" 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 < 8, so you will need to download it manually and extract it into the deps directory.

Disclaimer

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

codemasher/php-ext-xz 适用场景与选型建议

codemasher/php-ext-xz 是一款 基于 C 开发的 Composer 扩展包,目前已累计 115 次下载、GitHub Stars 达 17, 最近一次更新时间为 2025 年 09 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「lzma2」 「xz」 「php-extension」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 codemasher/php-ext-xz 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 codemasher/php-ext-xz 我们能提供哪些服务?
定制开发 / 二次开发

基于 codemasher/php-ext-xz 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 115
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 17
  • 点击次数: 29
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 17
  • Watchers: 1
  • Forks: 37
  • 开发语言: C

其他信息

  • 授权协议: PHP-3.01
  • 更新时间: 2025-09-12