[英]How to get phar archive meta-data inside of executed phar?
I have packaged PHP application into executable Phar archive and have there inside one Class with method which should access executed Phar archive
meta-data. 我已将PHP应用程序打包到可执行的Phar存档中,并且在一个Class内部有一个方法,该方法应该访问已执行的
Phar archive
元数据。
I could get meta-data as shown below however that seems odd that I load same Phar
inside the Phar archive
executed in order to get it's meta-data. 我可以获得如下所示的元数据,但是,为了获得它的元数据,我在
Phar archive
加载相同的Phar
似乎很奇怪。
So is there right way how to get executed Phar's meta-data? 那么,有没有正确的方式如何得到执行的Phar的元数据? Perhaps read it and defined that inside the Phar's Stub or something.
也许读它并在Phar的Stub里面定义一些东西。
<?php
namespace MyPhar;
use \Phar;
class InsideThePhar {
public function getPharMetaData() {
$phar_self = new Phar(Phar::running(false));
$metadata = $phar_self->getMetadata();
var_dump($metadata);
exit();
}
}
PHP keeps a cache of already loaded phar files, see http://git.php.net/?p=php-src.git;a=blob;f=ext/phar/phar.c;h=65ebce0f0856fc5a90a62d32dd0bb5c00627706f;hb=HEAD#l96 PHP保存已加载的phar文件的缓存,请参阅http://git.php.net/?p=php-src.git;a=blob;f=ext/phar/phar.c;h=65ebce0f0856fc5a90a62d32dd0bb5c00627706f; hb= HEAD#196
The cache is used when opening phar files, so it is not as expensive as opening a totally different phar file. 打开phar文件时使用缓存,因此它不像打开完全不同的phar文件那么昂贵。
And no, as of PHP 7.2 there is no better way to get the meta data of the currently "running" phar file. 不,从PHP 7.2开始,没有更好的方法来获取当前“正在运行”的phar文件的元数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.