Skip to content

Instantly share code, notes, and snippets.

@GaryRogers GaryRogers/createPhar.php
Last active Dec 23, 2018

Embed
What would you like to do?
Create a Phar archive for PHP
<?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
You can’t perform that action at this time.