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

我尝试根据命令定义部署过程:

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.

上一篇:知识点 | 分库分表情况下全局唯一主键的一种简单实现


下一篇:AOP__事务配置(简单代码xml配置,注解等)