我正在尝试创建一个非常简单的PHP CLI应用程序,该应用程序可以作为 phar 从命令行文件:
I'm trying to create a very simple PHP CLI application that can be run as a phar file from the command line:
# php myProject.phar这是我到目前为止尝试过的:
This is what I've tried so far:
我的项目位于名为MyProject的目录中,并且其中包含以下两个文件:
My project is in a directory called MyProject and it has these two files in it:
|-- createPhar.php `-- bootstrap.phpbootstrap.php
bootstrap.php文件包含以下内容:
bootstrap.php
The bootstrap.php file contains this:
<?php print phpversion() . PHP_EOL; print 'i am some script' . PHP_EOL;当我从Ubuntu命令行运行此脚本时:
When I run this script from my Ubuntu command line:
# cd MyProject # php bootstrap.php我得到以下输出:
5.3.2-1ubuntu4.9 i am some scriptcreatePhar.php
createPhar.php文件旨在将项目转换为Phar存档. 看起来像这样:
createPhar.php
The createPhar.php file is meant to turn the project into Phar archive. It looks like this:
<?php $phar = new Phar('MyProject.phar'); $phar->addFile('bootstrap.php'); $phar->setStub( $phar->createDefaultStub('bootstrap.php') );当我运行该脚本时...
When I run that script...
# php createPhar.php...在我的项目目录中创建了一个名为MyProject.phar的新文件.
... a new file called MyProject.phar is created in my project's directory.
|-- bootstrap.php |-- createPhar.php `-- MyProject.phar现在是问题所在
当我运行phar文件时...
Now here's the problem
When I run the phar file...
# php MyProject.phar...我希望看到与运行bootstrap.php脚本时得到的输出相同的输出.
...I expect to see the same the same output that I got when when I ran the bootstrap.php script.
相反,我什么也没看到.完全没有输出.这意味着$phar->createDefaultStub('bootstrap.php')
Instead I see nothing. No output at all. This implies that my bootstrap.php script is not being included by the default stub that was created by $phar->createDefaultStub('bootstrap.php')
我认为我误会了Phars及其存根的创建方式.请您解释一下我出了什么问题.
I think I am misunderstanding how Phars and their stubs are being created. Could you, please, explain where I have gone wrong.
推荐答案回答我自己的问题.
上面我的问题中概述的方法是创建phar/phar存根的一种正确方法.
The method outlined in my question, above, is one correct way to create a phar / phar stub.
它对我不起作用,对马里奥 did 不起作用的原因(请参阅问题下方的他的评论),是因为我安装了Suhosin,并且需要调整设置.
The reason why it did not work for me and did work for Mario (see his comment below the question), is because I had Suhosin installed and needed to tweak the settings.
使用此处概述的技术:
要修复,请输入:
To fix, put:
suhosin.executor.include.whitelist ="phar"
suhosin.executor.include.whitelist="phar"
在/etc/php5/cli/php.ini中
in /etc/php5/cli/php.ini
更多推荐
请说明如何创建PHP的Phar存根
发布评论