php8.5
Home/ Manual/ phar / Phar/ Phar::canCompress

Phar::canCompress

PHP function Edit on GitHub ✎

(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL phar >= 1.0.0)

Returns whether phar extension supports compression using either zlib or bzip2

Description

Phar::canCompress(int $compression = 0): bool

This should be used to test whether compression is possible prior to loading a phar archive containing compressed files.

Parameters

compression

Either Phar::GZ or Phar::BZ2 can be used to test whether compression is possible with a specific compression algorithm (zlib or bzip2).

Return Values

true if compression/decompression is available, false if not.

Examples

A Phar::canCompress() example

php
<?php
if (Phar::canCompress()) {
    echo file_get_contents('phar://compressedphar.phar/internal/file.txt');
} else {
    echo 'no compression available';
}
?>

See Also

Source: reference/phar/Phar/canCompress.xml · from the official PHP manual (php/doc-en)