ArticleslgStudy

science

PHAR (file format)

PHAR (file format) is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand PHAR (file format) rather than just read about it. In short: 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.

Key takeaways

  • PHAR (file format) belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect PHAR (file format) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of PHAR (file format) from memory before moving on to harder problems.

Reference excerpt

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.

History Created in 2004, PHAR files were influenced by Java's JAR file format with the aim of speeding up deployment of applications via FTP. 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 as a proof of concept. On June 14, 2004 the initial PHP_Archive package was proposed to PEAR and on December 13, 2004 it was accepted unanimously.

PHAR Extension In 2007, PHP_Archive was ported to C and released as a PECL extension. The extension was included and enabled by default in PHP 5.3.0.

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

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 Manifest — The manifest details the contents of the archive File Contents — The original files that are included in the archive Additionally, the PHAR format may also include a signature for verifying PHAR integrity.

Manifest 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. Each file has its own manifest within a segment of the global manifest. The current format is version 1.1.1.

Compression 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 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.

Usage 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.

References

External links PHAR File Format PHAR Documentation PHP_Archive PEAR Package PHAR Extension (PECL)

Worked examples

Example 1 — a first encounter with PHAR (file format)

Start with the simplest possible case. Write down what PHAR (file format) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to PHAR (file format) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about PHAR (file format) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of PHAR (file format)

In research
PHAR (file format) appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses PHAR (file format) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
PHAR (file format) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Archive formats, so understanding it makes those chapters shorter.
In everyday life
Look for PHAR (file format) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “PHAR (file format)” →

How to study PHAR (file format) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what PHAR (file format) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain PHAR (file format) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is PHAR (file format) in simple terms?

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 compati…

Why does PHAR (file format) matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study PHAR (file format)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on PHAR (file format).

Tags

  • Archive formats

Keep exploring