質問

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.

The index.php file will act as a "thin" dispatcher to N-file.php inside the phar archive.

Example of 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 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 (e.g. via command line parameter).

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:

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.

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. It installs the index.php and then uses the phar to load your application. 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. If you use webPhar() in the stub of your phar the request from your webserver is routed to your phar.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top