質問

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?

役に立ちましたか?

解決

You can use it:

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

As in docs.

他のヒント

I've done a bit of research on the matter and it seems it is impossible without incurring too much overhead.

The only plausible way I've found is by opening the "suspect" gotten from $argv[0] and check by inspecting the contents - however, that involves a lot of extra disk IO.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top