PHP Phar context options


Introduction

Phar stands for PHP Archive. All the resources of a certain PHP application or library are packages in a single .phar file for the purpose of istribution. A phar file can be used as IO stream with phar:// wrapper. Context options for phar:// wrapper are listed as follows −

compress

PHP has following predefined constants for defining compression formats

ConstantValueDescription
Phar::NONE0x00000000no compression
Phar::COMPRESSED0x0000F000bitmask with file flags to determine if any compression is presen
Phar::GZ0x00001000zlib (gzip) compression
Phar::BZ20x00002000bzip2 compression

metadata

Any PHP variable containing information to store that describes the phar archive is used as argument for Phar::setMetadata() method

Example

This example Phar context option set for creating Phar file

<?php
$context = stream_context_create(array('phar' =>
array('compress' => Phar::GZ)),
array('metadata' => array('user' => 'cellog')));
file_put_contents('phar://my.phar/somefile.php', 0, $context);
?>

Updated on: 21-Sep-2020

119 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements