PHAR (file format)

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
PHP Archive
Filename extension.phar
Developed byPHP, Davey Shafik, Greg Beaver, Marcus Börger
Type of formatFile archive, data compression
Extended fromZIP, tar

In software, a PHAR (PHP Archive) file is a package format to enable distribution of applications and libraries by bundling many PHP code files and other resources (e.g. images, stylesheets, etc.) into a single archive file.

PHAR files may be in one of three formats: tar, and ZIP, which are compatible with their respective tooling, and a custom PHAR format. Regardless of the format used, all PHAR files use the .phar file extension. Tar and Zip format archives may be created and unpacked using standard tar and zip utilities, while the PHAR format requires custom PHP code using the PHAR extension for PHP, or the PEAR PHP_Archive package.


Created in 2004, PHAR files were influenced[1] by Java's JAR file format with the aim of speeding up deployment of applications via FTP.[1] Rather than using the ZIP file format the simpler tar format was used, and the first PHAR was created using the tar command line utility[1] as a proof of concept. On June 14, 2004[2] the initial PHP_Archive package was proposed to PEAR and on December 13, 2004 it was accepted unanimously.[3]

PHAR Extension[edit]

In 2007, PHP_Archive was ported to C and released as a PECL extension.[4] The extension was included and enabled by default in PHP 5.3.0.[5][6]


A PHAR file allows for a Tar, Zip or PHAR formatted archive. Regardless of format, each archive contains three sections:

  1. Stub — A PHP file that will bootstrap the archive. The stub must contain the __HALT_COMPILER(); token, and the default stub includes the ability to run a PHAR with or without the PHP extension enabled[7]
  2. Manifest — The manifest details the contents of the archive
  3. File Contents — The original files that are included in the archive

Additionally, the PHAR format may also include a signature for verifying PHAR integrity.


The manifest contains meta-data information about the archive, and its contents. The binary format is intended to be efficient to parse in both PHP and C. It consists of fixed length segments, in addition to pairs of length specifications followed by variable length segments.[8] Each file has its own manifest within a segment of the global manifest. The current format is version 1.1.1.


All three formats have support for compression, however only the PHAR format supports both per-file and whole archive compression. Zip and Tar formats only support per-file and whole file compression respectively.

Executing PHAR files[edit]

Assuming the PHAR extension is enabled, all PHAR files may be executed simply by executing them with the PHP interpreter ("php file.phar"). If the PHAR extension is not enabled, only PHAR format can be executed.

Additionally, it is possible to mark a PHAR file as executable, and to add an appropriate shebang to make the PHAR executable directly.


While PHAR was originally intended for web usage, it is often used by command line utilities. Popular applications distributed in PHAR format, include Composer and PHPUnit.


  1. ^ a b c "PHP 5.3 5th Anniversary: The History of PHP Archives (PHAR Files)". Retrieved 2016-06-16.
  2. ^ "PEPr :: Details :: PHP_Archive". Retrieved 2016-06-16.
  3. ^ "PEPr :: Votes :: PHP_Archive". Retrieved 2016-06-16.
  4. ^ "PECL :: Package :: phar". Retrieved 2016-06-16.
  5. ^ "PHP: News Archive - 2009". Retrieved 2016-06-16.
  6. ^ "PHP: PHP 5 ChangeLog". Retrieved 2016-06-16.
  7. ^ "PHP: Phar::createDefaultStub - Manual". Retrieved 2016-06-17.
  8. ^ "PHP: Phar File Format - Manual". Retrieved 2016-06-17.

External links[edit]