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.
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.
So is there right way how to get executed Phar's meta-data? Perhaps read it and defined that inside the Phar's Stub or something.
<?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();
}
}
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 * .
The most common usage for a phar archive is to distribute a complete application in a single file. For instance, the PEAR Installer that is bundled with PHP versions is distributed as a phar archive. To use a phar archive distributed in this way, the archive can be executed on the command-line or via a web server.
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
The cache is used when opening phar files, so it is not as expensive as opening a totally different phar file.
And no, as of PHP 7.2 there is no better way to get the meta data of the currently "running" phar file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With