call with
php -dphar.readonly=0 create-phar.php
Last active
February 15, 2020 07:57
-
-
Save aloyr/4d8489cc82d085467d8ba1383178205b to your computer and use it in GitHub Desktop.
Phar template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// source: https://odan.github.io/2017/08/16/create-a-php-phar-file.html | |
// The php.ini setting phar.readonly must be set to 0 | |
$pharFile = 'app.phar'; | |
// clean up | |
if (file_exists($pharFile)) { | |
unlink($pharFile); | |
} | |
if (file_exists($pharFile . '.gz')) { | |
unlink($pharFile . '.gz'); | |
} | |
// create phar | |
$p = new Phar($pharFile); | |
// creating our library using whole directory | |
$p->buildFromDirectory('src/'); | |
// pointing main file which requires all classes | |
$p->setDefaultStub('index.php', '/index.php'); | |
// plus - compressing it into gzip | |
$p->compress(Phar::GZ); | |
echo "$pharFile successfully created"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// source: https://odan.github.io/2017/08/16/create-a-php-phar-file.html | |
// Filename: src/index.php | |
// Optional load composer autoloader | |
//require_once __DIR__ . '/vendor/autoload.php'; | |
echo "App started"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment