lzf_optimized_for
Introduction
Compression and Archive Extensions
PHP Manual

# Phar

Table of Contents

- Introduction
- Installing/Configuring
  - Requirements
  - Installation
  - Runtime Configuration
  - Resource Types
- Predefined Constants
- Using Phar Archives
  - Using Phar Archives: Introduction
  - Using Phar Archives: the phar stream wrapper
  - Using Phar Archives: the Phar and PharData class
- Creating Phar Archives
  - Creating Phar Archives: Introduction
- What makes a phar a phar and not a tar or a zip?
  - Ingredients of all Phar archives, independent of file format
  - Phar file stub
  - Head-to-head comparison of Phar, Tar and Zip
  - Tar-based phars
  - Zip-based phars
  - Phar File Format
  - Global Phar bitmapped flags
  - Phar manifest file entry definition
  - Phar Signature format
- Phar — The Phar class
  - Phar::addEmptyDir — Add an empty directory to the phar archive
  - Phar::addFile — Add a file from the filesystem to the phar archive
  - Phar::addFromString — Add a file from the filesystem to the phar archive
  - Phar::apiVersion — Returns the api version
  - Phar::buildFromDirectory — Construct a phar archive from the files within a directory.
  - Phar::buildFromIterator — Construct a phar archive from an iterator.
  - Phar::canCompress — Returns whether phar extension supports compression using either zlib or bzip2
  - Phar::canWrite — Returns whether phar extension supports writing and creating phars
  - Phar::compress — Compresses the entire Phar archive using Gzip or Bzip2 compression
  - Phar::compressAllFilesBZIP2 — Compresses all files in the current Phar archive using Bzip2 compression
  - Phar::compressAllFilesGZ — Compresses all files in the current Phar archive using Gzip compression
  - Phar::compressFiles — Compresses all files in the current Phar archive
  - Phar::__construct — Construct a Phar archive object
  - Phar::convertToData — Convert a phar archive to a non-executable tar or zip file
  - Phar::convertToExecutable — Convert a phar archive to another executable phar archive file format
  - Phar::copy — Copy a file internal to the phar archive to another new file within the phar
  - Phar::count — Returns the number of entries (files) in the Phar archive
  - Phar::createDefaultStub — Create a phar-file format specific stub
  - Phar::decompress — Decompresses the entire Phar archive
  - Phar::decompressFiles — Decompresses all files in the current Phar archive
  - Phar::delMetadata — Deletes the global metadata of the phar
  - Phar::delete — Delete a file within a phar archive
  - Phar::extractTo — Extract the contents of a phar archive to a directory
  - Phar::getMetadata — Returns phar archive meta-data
  - Phar::getModified — Return whether phar was modified
  - Phar::getSignature — Return MD5/SHA1/SHA256/SHA512/OpenSSL signature of a Phar archive
  - Phar::getStub — Return the PHP loader or bootstrap stub of a Phar archive
  - Phar::getSupportedCompression — Return array of supported compression algorithms
  - Phar::getSupportedSignatures — Return array of supported signature types
  - Phar::getVersion — Return version info of Phar archive
  - Phar::hasMetadata — Returns whether phar has global meta-data
  - Phar::interceptFileFuncs — instructs phar to intercept fopen, file_get_contents, opendir, and all of the stat-related functions
  - Phar::isBuffering — Used to determine whether Phar write operations are being buffered, or are flushing directly to disk
  - Phar::isCompressed — Returns Phar::GZ or PHAR::BZ2 if the entire phar archive is compressed (.tar.gz/tar.bz and so on)
  - Phar::isFileFormat — Returns true if the phar archive is based on the tar/phar/zip file format depending on the parameter
  - Phar::isValidPharFilename — Returns whether the given filename is a valid phar filename
  - Phar::isWritable — Returns true if the phar archive can be modified
  - Phar::loadPhar — Loads any phar archive with an alias
  - Phar::mapPhar — Reads the currently executed file (a phar) and registers its manifest
  - Phar::mount — Mount an external path or file to a virtual location within the phar archive
  - Phar::mungServer — Defines a list of up to 4 $_SERVER variables that should be modified for execution
  - Phar::offsetExists — determines whether a file exists in the phar
  - Phar::offsetGet — Gets a PharFileInfo object for a specific file
  - Phar::offsetSet — set the contents of an internal file to those of an external file
  - Phar::offsetUnset — remove a file from a phar
  - Phar::running — Returns the full path on disk or full phar URL to the currently executing Phar archive
  - Phar::setAlias — Set the alias for the Phar archive
  - Phar::setDefaultStub — Used to set the PHP loader or bootstrap stub of a Phar archive to the default loader
  - Phar::setMetadata — Sets phar archive meta-data
  - Phar::setSignatureAlgorithm — set the signature algorithm for a phar and apply it.
  - Phar::setStub — Used to set the PHP loader or bootstrap stub of a Phar archive
  - Phar::startBuffering — Start buffering Phar write operations, do not modify the Phar object on disk
  - Phar::stopBuffering — Stop buffering write requests to the Phar archive, and save changes to disk
  - Phar::uncompressAllFiles — Uncompresses all files in the current Phar archive
  - Phar::unlinkArchive — Completely remove a phar archive from disk and from memory
  - Phar::webPhar — mapPhar for web-based phars. front controller for web applications
- PharData — The PharData class
  - PharData::addEmptyDir — Add an empty directory to the tar/zip archive
  - PharData::addFile — Add a file from the filesystem to the tar/zip archive
  - PharData::addFromString — Add a file from the filesystem to the tar/zip archive
  - PharData::buildFromDirectory — Construct a tar/zip archive from the files within a directory.
  - PharData::buildFromIterator — Construct a tar or zip archive from an iterator.
  - PharData::compress — Compresses the entire tar/zip archive using Gzip or Bzip2 compression
  - PharData::compressFiles — Compresses all files in the current tar/zip archive
  - PharData::__construct — Construct a non-executable tar or zip archive object
  - PharData::convertToData — Convert a phar archive to a non-executable tar or zip file
  - PharData::convertToExecutable — Convert a non-executable tar/zip archive to an executable phar archive
  - PharData::copy — Copy a file internal to the phar archive to another new file within the phar
  - PharData::decompress — Decompresses the entire Phar archive
  - PharData::decompressFiles — Decompresses all files in the current zip archive
  - PharData::delMetadata — Deletes the global metadata of a zip archive
  - PharData::delete — Delete a file within a tar/zip archive
  - PharData::extractTo — Extract the contents of a tar/zip archive to a directory
  - PharData::isWritable — Returns true if the tar/zip archive can be modified
  - PharData::offsetSet — set the contents of a file within the tar/zip to those of an external file or string
  - PharData::offsetUnset — remove a file from a tar/zip archive
  - PharData::setAlias — dummy function (Phar::setAlias is not valid for PharData)
  - PharData::setDefaultStub — dummy function (Phar::setDefaultStub is not valid for PharData)
  - Phar::setMetadata — Sets phar archive meta-data
  - Phar::setSignatureAlgorithm — set the signature algorithm for a phar and apply it. The
  - PharData::setStub — dummy function (Phar::setStub is not valid for PharData)
- PharFileInfo — The PharFileInfo class
  - PharFileInfo::chmod — Sets file-specific permission bits
  - PharFileInfo::compress — Compresses the current Phar entry with either zlib or bzip2 compression
  - PharFileInfo::__construct — Construct a Phar entry object
  - PharFileInfo::decompress — Decompresses the current Phar entry within the phar
  - PharFileInfo::delMetadata — Deletes the metadata of the entry
  - PharFileInfo::getCRC32 — Returns CRC32 code or throws an exception if CRC has not been verified
  - PharFileInfo::getCompressedSize — Returns the actual size of the file (with compression) inside the Phar archive
  - PharFileInfo::getMetadata — Returns file-specific meta-data saved with a file
  - PharFileInfo::getPharFlags — Returns the Phar file entry flags
  - PharFileInfo::hasMetadata — Returns the metadata of the entry
  - PharFileInfo::isCRCChecked — Returns whether file entry has had its CRC verified
  - PharFileInfo::isCompressed — Returns whether the entry is compressed
  - PharFileInfo::isCompressedBZIP2 — Returns whether the entry is compressed using bzip2
  - PharFileInfo::isCompressedGZ — Returns whether the entry is compressed using gz
  - PharFileInfo::setCompressedBZIP2 — Compresses the current Phar entry within the phar using Bzip2 compression
  - PharFileInfo::setCompressedGZ — Compresses the current Phar entry within the phar using gz compression
  - PharFileInfo::setMetadata — Sets file-specific meta-data saved with a file
  - PharFileInfo::setUncompressed — Uncompresses the current Phar entry within the phar, if it is compressed
- PharException — The PharException class
  - PharException — The PharException class provides a phar-specific exception class for try/catch blocks.

# The Phar class

## Introduction

The Phar class provides a high-level interface to accessing and creating phar archives.

## Class synopsis

Phar
class Phar extends RecursiveDirectoryIterator implements Countable , ArrayAccess {
/* Methods */
public void addEmptyDir ( string `$dirname` )
public void addFile ( string `$file` [, string `$localname` ] )
public void addFromString ( string `$localname` , string `$contents` )
final public static string apiVersion ( void )
public array buildFromDirectory ( string `$base_dir` [, string `$regex` ] )
public array buildFromIterator ( Iterator `$iter` [, string `$base_directory` ] )
final public static bool canCompress ([ int `$type` = 0 ] )
final public static bool canWrite ( void )
public object compress ( int `$compression` [, string `$extension` ] )
public bool compressAllFilesBZIP2 ( void )
public bool compressAllFilesGZ ( void )
public void compressFiles ( int `$compression` )
public __construct ( string `$fname` [, int `$flags` [, string `$alias` ]] )
public PharData convertToData ([ int `$format` = 9021976 [, int `$compression` = 9021976 [, string `$extension` ]]] )
public Phar convertToExecutable ([ int `$format` = 9021976 [, int `$compression` = 9021976 [, string `$extension` ]]] )
public bool copy ( string `$oldfile` , string `$newfile` )
public int count ( void )
final public static string createDefaultStub ([ string `$indexfile` [, string `$webindexfile` ]] )
public object decompress ([ string `$extension` ] )
public bool decompressFiles ( void )
public bool delMetadata ( void )
public bool delete ( string `$entry` )
public bool extractTo ( string `$pathto` [, string|array `$files` [, bool `$overwrite` = false ]] )
public mixed getMetadata ( void )
public bool getModified ( void )
public array getSignature ( void )
public string getStub ( void )
final public static array getSupportedCompression ( void )
final public static array getSupportedSignatures ( void )
public string getVersion ( void )
public bool hasMetadata ( void )
final public static void interceptFileFuncs ( void )
public bool isBuffering ( void )
public mixed isCompressed ( void )
public bool isFileFormat ( int `$format` )
final public static bool isValidPharFilename ( string `$filename` [, bool `$executable` = true ] )
public bool isWritable ( void )
final public static bool loadPhar ( string `$filename` [, string `$alias` ] )
final public static bool mapPhar ([ string `$alias` [, int `$dataoffset` = 0 ]] )
final public static void mount ( string `$pharpath` , string `$externalpath` )
final public static void mungServer ( array `$munglist` )
public bool offsetExists ( string `$offset` )
public int offsetGet ( string `$offset` )
public void offsetSet ( string `$offset` , string `$value` )
public bool offsetUnset ( string `$offset` )
final public static string running ([ bool `$retphar` = true ] )
public bool setAlias ( string `$alias` )
public bool setDefaultStub ([ string `$index` [, string `$webindex` ]] )
public void setMetadata ( mixed `$metadata` )
public void setSignatureAlgorithm ( int `$sigtype` [, string `$privatekey` ] )
public bool setStub ( string `$stub` [, int `$len` = -1 ] )
public void startBuffering ( void )
public void stopBuffering ( void )
public bool uncompressAllFiles ( void )
final public static bool unlinkArchive ( string `$archive` )
final public static void webPhar ([ string `$alias` [, string `$index` = "index.php" [, string `$f404` [, array `$mimetypes` [, callable `$rewrites` ]]]]] )
}

# The PharData class

## Introduction

The PharData class provides a high-level interface to accessing and creating non-executable tar and zip archives. Because these archives do not contain a stub and cannot be executed by the phar extension, it is possible to create and manipulate regular zip and tar files using the PharData class even if phar.readonly php.ini setting is 1.

## Class synopsis

PharData
class PharData extends Phar {
/* Methods */
bool addEmptyDir ( string `$dirname` )
public void Phar::addFile ( string `$file` [, string `$localname` ] )
bool addFromString ( string `$localname` , string `$contents` )
public array Phar::buildFromDirectory ( string `$base_dir` [, string `$regex` ] )
array buildFromIterator ( Iterator `$iter` [, string `$base_directory` ] )
object compress ( int `$compression` [, string `$extension` ] )
bool compressFiles ( int `$compression` )
__construct ( string `$fname` [, int `$flags` [, string `$alias` [, int `$format` = `Phar::TAR` ]]] )
PharData convertToData ([ int `$format` [, int `$compression` [, string `$extension` ]]] )
Phar convertToExecutable ([ int `$format` [, int `$compression` [, string `$extension` ]]] )
bool copy ( string `$oldfile` , string `$newfile` )
object decompress ([ string `$extension` ] )
bool decompressFiles ( void )
bool delMetadata ( void )
bool delete ( string `$entry` )
bool extractTo ( string `$pathto` [, string|array `$files` [, bool `$overwrite` = false ]] )
bool isWritable ( void )
void offsetSet ( string `$offset` , string `$value` )
bool offsetUnset ( string `$offset` )
bool setAlias ( string `$alias` )
bool setDefaultStub ([ string `$index` [, string `$webindex` ]] )
public void Phar::setMetadata ( mixed `$metadata` )
public void Phar::setSignatureAlgorithm ( int `$sigtype` )
bool setStub ( string `$stub` [, int `$len` = -1 ] )
/* Inherited methods */
public void Phar::addEmptyDir ( string `$dirname` )
public void Phar::addFile ( string `$file` [, string `$localname` ] )
public void Phar::addFromString ( string `$localname` , string `$contents` )
final public static string Phar::apiVersion ( void )
public array Phar::buildFromDirectory ( string `$base_dir` [, string `$regex` ] )
public array Phar::buildFromIterator ( Iterator `$iter` [, string `$base_directory` ] )
final public static bool Phar::canCompress ([ int `$type` = 0 ] )
final public static bool Phar::canWrite ( void )
public object Phar::compress ( int `$compression` [, string `$extension` ] )
public bool Phar::compressAllFilesBZIP2 ( void )
public bool Phar::compressAllFilesGZ ( void )
public void Phar::compressFiles ( int `$compression` )
public Phar::__construct ( string `$fname` [, int `$flags` [, string `$alias` ]] )
public PharData Phar::convertToData ([ int `$format` = 9021976 [, int `$compression` = 9021976 [, string `$extension` ]]] )
public Phar Phar::convertToExecutable ([ int `$format` = 9021976 [, int `$compression` = 9021976 [, string `$extension` ]]] )
public bool Phar::copy ( string `$oldfile` , string `$newfile` )
public int Phar::count ( void )
final public static string Phar::createDefaultStub ([ string `$indexfile` [, string `$webindexfile` ]] )
public object Phar::decompress ([ string `$extension` ] )
public bool Phar::decompressFiles ( void )
public bool Phar::delMetadata ( void )
public bool Phar::delete ( string `$entry` )
public bool Phar::extractTo ( string `$pathto` [, string|array `$files` [, bool `$overwrite` = false ]] )
public mixed Phar::getMetadata ( void )
public bool Phar::getModified ( void )
public array Phar::getSignature ( void )
public string Phar::getStub ( void )
final public static array Phar::getSupportedCompression ( void )
final public static array Phar::getSupportedSignatures ( void )
public string Phar::getVersion ( void )
public bool Phar::hasMetadata ( void )
final public static void Phar::interceptFileFuncs ( void )
public bool Phar::isBuffering ( void )
public mixed Phar::isCompressed ( void )
public bool Phar::isFileFormat ( int `$format` )
final public static bool Phar::isValidPharFilename ( string `$filename` [, bool `$executable` = true ] )
public bool Phar::isWritable ( void )
final public static bool Phar::loadPhar ( string `$filename` [, string `$alias` ] )
final public static bool Phar::mapPhar ([ string `$alias` [, int `$dataoffset` = 0 ]] )
final public static void Phar::mount ( string `$pharpath` , string `$externalpath` )
final public static void Phar::mungServer ( array `$munglist` )
public bool Phar::offsetExists ( string `$offset` )
public int Phar::offsetGet ( string `$offset` )
public void Phar::offsetSet ( string `$offset` , string `$value` )
public bool Phar::offsetUnset ( string `$offset` )
final public static string Phar::running ([ bool `$retphar` = true ] )
public bool Phar::setAlias ( string `$alias` )
public bool Phar::setDefaultStub ([ string `$index` [, string `$webindex` ]] )
public void Phar::setMetadata ( mixed `$metadata` )
public void Phar::setSignatureAlgorithm ( int `$sigtype` [, string `$privatekey` ] )
public bool Phar::setStub ( string `$stub` [, int `$len` = -1 ] )
public void Phar::startBuffering ( void )
public void Phar::stopBuffering ( void )
public bool Phar::uncompressAllFiles ( void )
final public static bool Phar::unlinkArchive ( string `$archive` )
final public static void Phar::webPhar ([ string `$alias` [, string `$index` = "index.php" [, string `$f404` [, array `$mimetypes` [, callable `$rewrites` ]]]]] )
}

# The PharFileInfo class

## Introduction

The PharFileInfo class provides a high-level interface to the contents and attributes of a single file within a phar archive.

## Class synopsis

PharFileInfo
class PharFileInfo extends SplFileInfo {
/* Methods */
public void chmod ( int `$permissions` )
public bool compress ( int `$compression` )
public __construct ( string `$entry` )
public bool decompress ( void )
public bool delMetadata ( void )
public int getCRC32 ( void )
public int getCompressedSize ( void )
public mixed getMetadata ( void )
public int getPharFlags ( void )
public bool hasMetadata ( void )
public bool isCRCChecked ( void )
public bool isCompressed ([ int `$compression_type` = 9021976 ] )
public bool isCompressedBZIP2 ( void )
public bool isCompressedGZ ( void )
public bool setCompressedBZIP2 ( void )
public bool setCompressedGZ ( void )
public void setMetadata ( mixed `$metadata` )
public bool setUncompressed ( void )
}

# The PharException class

## Introduction

The PharException class provides a phar-specific exception class for try/catch blocks.

## Class synopsis

PharException
class PharException extends Exception {
/* Inherited properties */
protected string $message ;
protected int $code ;
protected string $file ;
protected int $line ;
/* Inherited methods */
final public string Exception::getMessage ( void )
final public Exception Exception::getPrevious ( void )
final public mixed Exception::getCode ( void )
final public string Exception::getFile ( void )
final public int Exception::getLine ( void )
final public array Exception::getTrace ( void )
final public string Exception::getTraceAsString ( void )
public string Exception::__toString ( void )
final private void Exception::__clone ( void )
}