简体   繁体   English

Phar存档和存根文件用法

[英]Phar archive and stub file usage

I try to define a deployment procedure based on command : 我尝试根据命令定义部署过程:

php <phar_file_deployed_on_server>.phar

This command generates an index.php file external to phar archive. 此命令生成phar存档外部的index.php文件。

The index.php file will act as a "thin" dispatcher to N-file.php inside the phar archive. index.php文件将充当phar存档中N-file.php的“瘦”调度程序。

Example of generated index.php file : 生成的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();

?>

The above dispathing rule is an example. 上述调度规则就是一个例子。

My idea is oriented to simply the deployment procedure. 我的想法仅仅是面向部署过程。 The example provided check $_GET array, but it's possible a more complex rule generated during deployment (eg via command line parameter). 该示例提供了check $ _GET数组,但是在部署期间可能会生成更复杂的规则(例如,通过命令行参数)。

I have created a PHP web application and compressed it to the Phar format for easy deployment. 我创建了一个PHP Web应用程序并将其压缩为Phar格式以便于部署。

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. 应用程序可以在生产机器上无需解压缩的情况下执行,因为我已经计划了一个index.php文件,该文件链接到Phar存档中的应用程序。

To generate the index.php file during deployment, it is necessary to launch the following command into production machine shell: 要在部署期间生成index.php文件,必须将以下命令启动到生产机器shell中:

 php <just_deployed_phar_file> 

The code inside the stub file generates the index.php file in manner to refer to the just installed Phar archive. 存根文件中的代码以引用刚刚安装的Phar存档的方式生成index.php文件。

Is this the correct way to use the stub file? 这是使用存根文件的正确方法吗?

You can use the stub file to do whatever you want to do. 您可以使用存根文件执行您想要执行的任何操作。 When the phar is executed (with php xxx.phar) If I get your question right, you're planning to use your phar file as an installer for your whole application. 当执行phar时(使用php xxx.phar)如果我的问题正确,那么您计划将phar文件用作整个应用程序的安装程序。 It installs the index.php and then uses the phar to load your application. 它安装index.php,然后使用phar加载您的应用程序。 That would do its job, but there is a better way: 这样做会有所作为,但还有更好的方法:

I think you're searching for webPhar , which acts like a frontcontroller for your application. 我想你正在寻找webPhar ,它就像你的应用程序的前控制器一样。 If you use webPhar() in the stub of your phar the request from your webserver is routed to your phar. 如果您在phar的存根中使用webPhar(),则来自您的网络服务器的请求将被路由到您的phar。

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

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