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

Constant Value Description
Phar::NONE 0x00000000 no compression
Phar::COMPRESSED 0x0000F000 bitmask with file flags to determine if any compression is presen
Phar::GZ 0x00001000 zlib (gzip) compression
Phar::BZ2 0x00002000 bzip2 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: 2020-09-21T09:28:45+05:30

209 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements