简体   繁体   English

phar文件的路径是什么

[英]What is the path to a phar file

I have created a phar file of my framework. 我已经创建了框架的phar文件。 The way you run cron-jobs in the framework is by calling executing the pharfile on the command line: 在框架中运行cron-jobs的方式是通过在命令行上调用执行pharfile:

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. 归档文件中的引导文件用于将_ FILE _的路径与已执行命令的解析路径进行比较,以确定该文件已直接执行。

The question is: Is it possible to get the filename of the phar-file from within the phar file, and how? 问题是:是否有可能从phar文件中获取phar文件的文件名,怎么办?

That is: what is the alternative to _ FILE _ in phar-files? 也就是说:在phar文件中, _ FILE _的替代方法是什么?

You can use it: 您可以使用它:

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

As in docs . 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. 我发现的唯一可行的方法是,打开从$ argv [0]获得的“可疑”并通过检查内容进行检查-但是,这涉及大量额外的磁盘IO。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM