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

Phar, the PHP .exe format - DPC, June, 2012

Phar, the PHP .exe format - DPC, June, 2012

Learn about what the PHAR (PHP Archives) format is all about. A PHAR is conceptually similar to a Java JAR but made to fit PHP's needs.

Hear how to use it to distribute your product to clients, why open source projects have started offering their projects as a PHAR file, run your application directly from the PHAR container without extracting anything to the filesystem, secure it using the signature feature to ensure the container hasn't been tampered with and many other interesting features.

By the end of it you will be wanting to use PHAR for CLI and Web apps alike!

Helgi Þorbjörnsson

June 09, 2012
Tweet

More Decks by Helgi Þorbjörnsson

Other Decks in Programming

Transcript

  1. PEAR: PHP_Archive ‣ Reference implementation ‣ User Land Code ‣

    Less Powerful ‣ Works on older PHP ‣ Not maintained anymore
  2. Streams Usage fopen / fwrite / fclose file_get_contents opendir /

    rmdir / mkdir anything that works with streams
  3. if (!Phar::canWrite()) { die("Read-only, php -d phar.readonly=0 web/create.php\n"); } $p

    = new Phar(__DIR__ . '/project.phar', 0, 'project.phar'); $p->buildFromDirectory('/path/to/project'); $stub = <<<'EOD' Stub Goes Here EOD; $p->setStub($stub);
  4. $phar = new Phar('project.phar', 0, 'project.phar'); $phar->buildFromIterator( new RecursiveIteratorIterator( new

    Phar('/path/to/anotherphar.phar') ), 'phar:///path/to/anotherphar.phar/path/to/project'); $stub = $phar->createDefaultStub('cli/index.php', 'index.php'); $phar->setStub($stub);
  5. ❖ Command line ❖ Web applications ❖ Setup tools ❖

    Plugins ❖ Themes ❖ Libraries Why use Phar?
  6. Pros Single download with all dependencies Run multiple versions in

    parallel Upgrades are easy No unpacking Security against modifications
  7. Cons Incremental updates (no deltas) Upgrading is a manual process

    Web server may need changes Extending the application is harder README / INSTALL become hard to reach
  8. PharData Phar archives can be extracted to disk Can operate

    on non-phar gzip and tar extract and compress archives Like PDO for archives! :-)