简体   繁体   English

PHP中PHAR存档的优势

[英]Advantages of PHAR archives in PHP

PHP 5.3 has a new feature called PHAR similar to JAR in JAVA. PHP 5.3具有一个称为PHAR的新功能,类似于JAVA中的JAR It's basically a archive of PHP files. 它基本上是PHP文件的存档。 What are its advantages? 它有什么优势? I can't understand how they can be helpful in the web scenario. 我无法理解它们如何在Web场景中提供帮助。

Any other use other than "ease of deployment" - deploy an entire application by just copying one file 除“易于部署”以外的任何其他用途-只需复制一个文件即可部署整个应用程序

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. 想象一下:您可以通过将CMS,论坛或博客系统拖到FTP客户端中来在其网站上安装它。 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. 如果您的Web主机不授予您Shell访问权限,则无需在上传前解压缩,从而节省了按文件传输的开销。

  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?). 您不需要弄清楚如何使用PEAR安装程序,也不需要弄清楚这个或那个库是否具有嵌套的目录结构,或者是否必须包括X,Y或Z(按此顺序?)。 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. 对于本地的SaaS来说,这没有什么区别,但是对于任何运送或安装PHP软件包的人来说,这都是改变游戏规则的事情。

In theory it should also improve loading speed. 从理论上讲,它还应该提高加载速度。 If you have alot of files which need to be included, replacing it with single include will save you time on file opening operations. 如果您有很多需要包含的文件,则用单个include替换它可以节省您打开文件的时间。

In my experience, loosely packaged PHP source files sitting in a production environment invite tinkering with live code when a fix is needed. 以我的经验,在生产环境中散装的PHP源文件会在需要修复时邀请修改实时代码。 Deploying in a .phar file discourages this behaviour and helps reinforce better practices, ie build and test in a local environment, then deploy to production. 在.phar文件中进行部署会阻止此行为,并有助于加强更好的做法,即在本地环境中进行构建和测试,然后再进行生产。

The advantage is mainly ease of deployment. 优点主要是易于部署。 You deploy an entire application by just copying one file. 您只需复制一个文件即可部署整个应用程序。

Libraries can also be used without being expanded. 库也可以在不扩展的情况下使用。

Any tool that works on a single file "suddenly" works with all files of an application at once. 任何在单个文件上“突然”使用的工具都可以一次与应用程序的所有文件一起使用。
Eg transport: You can upload the entire application through a single input/file element without additional steps. 例如,传输:您可以通过单个输入/文件元素上传整个应用程序,而无需执行其他步骤。
Eg signing an application: checksum/sign the file -> checksum/signature for the whole application. 例如,对应用程序签名:校验和/签名文件->整个应用程序的校验和/签名。
... ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM