PHP PHAR 归档的优点
PHP 5.3 有一个名为 PHAR 的新功能,类似于 JAVA 中的 JAR。它基本上是 PHP 文件的存档。它有什么优点?我不明白它们在网络场景中有何帮助。
除“易于部署”之外的任何其他用途 - 只需复制一个文件即可部署整个应用程序
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
开源项目有巨大的好处(排名不分先后)。
更轻松的部署意味着更容易采用。想象一下:您通过将 CMS、论坛或博客系统拖到 FTP 客户端来在您的网站上安装它。 就是这样。
更轻松的部署意味着更轻松的安全性。如果您只需要担心一个文件,则更新到最新版本的软件包会简单得多。
更快的部署。如果您的网站主机不提供 shell 访问权限,则您无需在上传前解压缩,这样就可以减少每个文件的传输开销。
先天的区隔。作为包一部分的文件与添加或自定义的文件明显不同。您知道您可以轻松替换存档,但您需要备份您的配置和自定义模板(并且它们不会全部混合在一起)。
更简单的库。您不需要弄清楚如何使用 PEAR 安装程序,或者查明这个或那个库是否具有嵌套目录结构,或者是否必须包含 X、Y 或 Z(按这个顺序?)。只需上传、包含存档、开始编码。
更容易维护。不确定更新库是否会破坏您的应用程序?只需更换它即可。破碎的?恢复一个文件。您甚至不需要接触您的应用程序。
所见即所得。很有可能,有人不会费尽心思去捏造存档,因此,如果您看到您维护的系统上安装了一个存档,您就可以相当有信心它没有被某人随机黑客攻击。哈希可以快速告诉您它是什么版本或是否已更改。
不要拉屎,让部署更容易。对于本土 SaaS 来说,它不会产生任何影响,但对于任何发布或安装 PHP 软件包的人来说,它是一个游戏规则改变者。
There are tremendous benefits for open source projects (in no particular order).
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.
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.
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.
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).
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.
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.
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.
理论上它也应该提高加载速度。如果您有很多需要包含的文件,则将其替换为单个包含将节省您打开文件操作的时间。
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.
根据我的经验,松散打包的 PHP 源文件位于生产环境中邀请在需要修复时修改实时代码。在 .phar 文件中进行部署可以阻止这种行为,并有助于强化更好的实践,即在本地环境中构建和测试,然后部署到生产环境。
In my experience, loosely packaged PHP source files sitting in a production environment invite tinkering with live code when a fix is needed. Deploying in a .phar file discourages this behaviour and helps reinforce better practices, i.e. build and test in a local environment, then deploy to production.
优点主要是易于部署。您只需复制一个文件即可部署整个应用程序。
库也可以在不扩展的情况下使用。
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.
E.g. transport: You can upload the entire application through a single input/file element without additional steps.
E.g. signing an application: checksum/sign the file -> checksum/signature for the whole application.
...