Last active
March 28, 2020 23:54
-
-
Save GaryRogers/d67c95dbf3e77c330bbf to your computer and use it in GitHub Desktop.
Create a Phar archive for PHP
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 | |
# Create an executable phar | |
# Name of our archive. | |
$phar = new Phar("myscript.phar"); | |
# Have to do buffering to make things executable. | |
# See http://stackoverflow.com/questions/11082337/how-to-make-an-executable-phar | |
$phar->startBuffering(); | |
# Default executable. | |
$defaultStub = $phar->createDefaultStub('bin/myscript.php'); | |
# Build from the project directory. Assumes that createPhar.php (this file) is in the project root. | |
$phar->buildFromDirectory(dirname(__FILE__)); | |
# Add the header to enable execution. | |
$stub = "#!/usr/bin/env php \n" . $defaultStub; | |
# Set the stub. | |
$phar->setStub($stub); | |
# Wrap up. | |
$phar->stopBuffering(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment