Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advantages of PHAR archives in PHP

Tags:

php

phar

PHP 5.3 has a new feature called PHAR similar to JAR in JAVA. It's basically a archive of PHP files. What are its advantages? I can't understand how they can be helpful in the web scenario.

Any other use other than "ease of deployment" - deploy an entire application by just copying one file

like image 762
aWebDeveloper Avatar asked Aug 19 '10 11:08

aWebDeveloper


People also ask

What is the use of Phar?

What is phar? Phar archives are best characterized as a convenient way to group several files into a single file. As such, a phar archive provides a way to distribute a complete PHP application in a single file and run it from that file without the need to extract it to disk.

What is Phar file in PHP?

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. PHP Archive.

How do I extract a Phar file?

To unpack the PHAR archive, you need to click on the area below or drag the * . phar file into it with the mouse. As a result of unpacking, you will receive a ZIP archive. To package the PHAR archive, you need to click on the area below or drag the * .


1 Answers

There are tremendous benefits for open source projects (in no particular order).

  1. Easier deployment means easier adoption. Imagine: You install a CMS, forum, or blog system on your website by dragging it into your FTP client. That's it.

  2. Easier deployment means easier security. Updating to the latest version of a software package will be much less complicated if you have only one file to worry about.

  3. Faster deployment. If your webhost doesn't give you shell access, you don't need to unzip before uploading, which cuts out per-file transfer overhead.

  4. Innate compartmentalization. Files that are part of the package are clearly distinguished from additions or customizations. You know you can easily replace the archive but you need to backup your config and custom templates (and they aren't all mixed together).

  5. Easier libraries. You don't need to figure out how to use the PEAR installer, or find out whether this or that library has a nested directory structure, or whether you have to include X, Y, or Z (in that order?). Just upload, include archive, start coding.

  6. Easier to maintain. Not sure whether updating a library will break your application? Just replace it. Broken? Revert one file. You don't even need to touch your application.

  7. What you see is what you get. Chances are, someone is not going to go to the trouble of fudging with an archive, so if you see one installed on a system you maintain, you can be fairly confident that it doesn't have someone's subtly buggy random hacks thrown in. And a hash can quickly tell you what version it is or whether it's been changed.

Don't poo-poo making it easier to deploy things. It won't make any difference for homegrown SaaS, but for anyone shipping or installing PHP software packages it's a game-changer.

like image 129
cbednarski Avatar answered Oct 03 '22 22:10

cbednarski