PHP code example of codemasher / php-ext-xz

1. Go to this page and download the library: Download codemasher/php-ext-xz library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

codemasher / php-ext-xz example snippets


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

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

$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 = '/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);

const COMPRESSION_LEVEL = 7;

$compressed = xzencode($string, COMPRESSION_LEVEL);

$wh = xzopen($file, 'w', COMPRESSION_LEVEL);
bash
pie install codemasher/php-ext-xz
bash
git clone https://github.com/codemasher/php-ext-xz.git
cd php-ext-xz
phpize
./configure
make
sudo make install
bat
git clone https://github.com/Microsoft/php-sdk-binary-tools.git c:\php-sdk
cd c:\php-sdk
phpsdk-vs16-x64.bat
bat
phpsdk_buildtree php-8.0
git clone https://github.com/php/php-src.git
cd php-src
git checkout PHP-8.0
bat
git clone https://github.com/codemasher/php-ext-xz .\ext\xz
phpsdk_deps -u
buildconf --force
configure --enable-xz
nmake snap