File archive and stub usage

I am trying to determine the deployment procedure based on the command:

php <phar_file_deployed_on_server>.phar 

This command creates an index.php file external to the phar archive.

The index.php file will act as a thin manager for the N-file.php inside the phar archive.

An example of the generated index.php file:

 <? $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 dispatch rule.

My idea is focused only on the deployment procedure. In the example, the $ _GET array is specified, but a more complex rule generated during deployment is possible (for example, via the command line parameter).

I created a PHP web application and compressed it into a Phar format for easy deployment.

An application can be executed without decompression in production because I planned the index.php file, which refers to the application in the Phar archive.

To generate the index.php file during deployment, run the following command in the shell of the working machine:

 php <just_deployed_phar_file> 

The code inside the stub file generates the index.php file in order to reference the newly installed Phar archive.

Is this the right way to use stubs?

+4
source share
1 answer

You can use the stub file to do whatever you want. When phar is running (with php xxx.phar) If I ask the question correctly, you plan to use your phar file as an installer for your entire application. It installs index.php and then uses phar to load your application. This would do its job, but there is a better way:

I think you are looking for a webPhar that acts as a frontcontroller for your application. If you use webPhar () in the stub of your phar, the request from your web server is sent to your phar.

+1
source

Source: https://habr.com/ru/post/1434842/


All Articles