Upgrade to Pro — share decks privately, control downloads, hide ads and more …



Christian Münch

July 21, 2017

More Decks by Christian Münch

Other Decks in Programming


  1. Was ist ein Phar Archiv? Phar archives are best characterized

    as a convenient way to group several files into a single file. As such, a phar archive provides a way to distribute a complete PHP application in a single file and run it from that file without the need to extract it to disk. Additionally, phar archives can be executed by PHP as easily as any other file, both on the commandline and from a web server. Phar is kind of like a thumb drive for PHP applications. http://www.php.net/manual/en/intro.phar.php Christian Münch / @cmuench 2
  2. Was ist in einer Phar Datei? ein Stub Ein Manifest,

    welches den Inhalt beschreibt Inhalte Eine Signatur zum Prüfen ob die Datei valide ist (optional) Christian Münch / @cmuench 3
  3. Historie PEAR Paket "PHP_Archive" 25 . Januar 2005 Damals aktuelle

    PHP Version -> 4.3.7 Registrierte phar:// Stream Reiner PHP Code Christian Münch / @cmuench 4
  4. Historie / Phar Reloaded 28.03.2007 PECL Package Implementierung in C

    SPL Integration APC Kompatibilität Damals aktuelle PHP Version 5.2 Christian Münch / @cmuench 5
  5. Status Quo Ab PHP 5.3 (30. Juni 2009) ist das

    Phar Modul in der Standard Distribution enthalten. Christian Münch / @cmuench 6
  6. Phar Datei erstellen $phar = new Phar('test.phar', 0, 'test.phar'); $phar->buildFromIterator(

    new RecursiveIteratorIterator( new RecursiveDirectoryIterator('src') ), '.' ); $phar->setStub( $phar->createDefaultStub( 'src/cli/index.php', 'src/web/index.php' ) ); Christian Münch / @cmuench 9
  7. Metadaten <?php try { $pharInfo = new \Phar('phar://test.phar'); var_dump($pharInfo->getMetadata()); $pharInfo->setMetadata(array('Created

    at' => 'PHPUG Rheinhessen')); } catch (\Exception $e) { echo $e->getMessage(); } Christian Münch / @cmuench 12
  8. Metadaten (pro Datei) <?php try { $pharFileInfo = new \PharFileInfo('phar://test.phar/src/a.php');

    var_dump($pharFileInfo->getContent()); var_dump($pharFileInfo->getMetadata()); var_dump($pharFileInfo->isCompressed()); $pharFileInfo->setMetadata(array('Created at' => 'PHPUG Rheinhessen')); } catch (\Exception $e) { echo $e->getMessage(); } Christian Münch / @cmuench 13
  9. Box http://box-project.org { "chmod": "0755", "directories": ["src"], "alias": "test.phar", "output":

    "test.phar", "stub": "src/cli/index.php" } Christian Münch / @cmuench 15
  10. Phing build.xml <?xml version="1.0"?> <project name="phar-create-example" default="dist"> <target name="dist"> <pharpackage

    basedir="${project.basedir}" compression="none" alias="test.phar" destfile="test.phar" clistub="src/cli/index.php" webstub="src/web/index.php" signature="true"> <fileset dir="src"> <include name="**" /> </fileset> </pharpackage> </target> </project> Christian Münch / @cmuench 17