加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – Phar存档和存根文件用法

发布时间:2020-12-13 22:45:07 所属栏目:PHP教程 来源:网络整理
导读:我尝试根据命令定义部署过程: php phar_file_deployed_on_server.phar 此命令生成phar存档外部的index.php文件. index.php文件将充当phar存档中N-file.php的“瘦”调度程序. 生成的index.php文件示例: ?$requiredFile = "phar://phar_file_deployed_on_ser
我尝试根据命令定义部署过程:

php <phar_file_deployed_on_server>.phar

此命令生成phar存档外部的index.php文件.

index.php文件将充当phar存档中N-file.php的“瘦”调度程序.

生成的index.php文件示例:

<?

$requiredFile = "phar://<phar_file_deployed_on_server>.phar";

/**
 * For example index.php can check $_GET array and dispatch 
 * to file inside Phar archive.
 **/
if (array_key_exists("getParameter",$_GET))
    $requiredFile = $requiredFile . "/" . $_GET['getParameter'] . ".php";
else
    <handling_of_else_condition>;

require_once $requiredFile;

__HALT_COMPILER();

?>

上述调度规则就是一个例子.

我的想法仅仅是面向部署过程.该示例提供了check $_GET数组,但是在部署期间可能会生成更复杂的规则(例如,通过命令行参数).

I have created a PHP web application and compressed it to the Phar
format for easy deployment.

The application can be executed without decompression on a production
machine,because I have planned an index.php file that links to the
application inside the Phar archive.

To generate the index.php file during deployment,it is necessary to
launch the following command into production machine shell:

06002

The code inside the stub file generates the index.php file in manner
to refer to the just installed Phar archive.

Is this the correct way to use the stub file?

解决方法

您可以使用存根文件执行您想要执行的任何操作.执行phar时(使用php xxx.phar)
如果我的问题是正确的,那么您计划将phar文件用作整个应用程序的安装程序.它安装index.php,然后使用phar加载您的应用程序.这样做会有所作为,但还有更好的方法:

我想你正在寻找webPhar,它就像你的应用程序的前控制器.如果您在phar的存根中使用webPhar(),则来自您的网络服务器的请求将被路由到您的phar.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读