Search code examples
phpphar

What is the path to a phar file


I have created a phar file of my framework. The way you run cron-jobs in the framework is by calling executing the pharfile on the command line:

php path/to/archive.phar cron -r /path/to/site

The bootstrap file in the archive used to compare the path of _FILE_ with the resolved path of the executed command to determine that it had been executed directly.

The question is: Is it possible to get the filename of the phar-file from within the phar file, and how?

That is: what is the alternative to _FILE_ in phar-files?


Solution

  • You can use it:

    <?php
    $a = Phar::running(); // $a is "phar:///path/to/my.phar"
    

    As in docs.