Sample code for 30+ languages & platforms
PHP

bz2 Compress File

Compress a file to the bz2 file format.

Chilkat PHP Downloads

Chilkat2 PHP
<?php

use Chilkat2\Bz2;

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

$bz2 = new Bz2();

// Compress the file qa_data/hamlet.xml to create qa_output/hamlet.bz2
try {
    $bz2->CompressFile('qa_data/hamlet.xml', 'qa_output/hamlet.bz2');
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

echo "Success.\n";