How to get phar archive metadata inside phar executable?

I packed the PHP application into the Phar executable archive and there, inside the same class as the method, which should access the executed metadata of the Phar archive .

I could get the metadata as shown below, however it seems strange that I load the same Phar inside the Phar archive , executed to get the metadata.

So, is there a way to get completed meta data from Phar? Perhaps read it and determine what is inside the Phar Stub or something else.

 <?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(); } } 
+5
source share
1 answer

PHP stores the 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

The cache is used when opening phar files, so it is not as expensive as opening a completely different phar file.


And no, with PHP 7.2 there is no better way to get the metadata of the current "running" phar file.

+1
source

Source: https://habr.com/ru/post/1242793/


All Articles