Phars are PHP Archives. Kind of like a Java JAR file, but for PHP uses. They're great for distributing executable command line utilities written in PHP. However, creating one is not the simplest thing ever.
16. $> php backup.phar
Using the PHAR
<?php
include 'phar://coollibrary.phar/internal/file.php';
header('Content-type: image/jpeg');
// phars can be accessed by full path or by alias
echo file_get_contents('phar:///fullpath/to/coollibrary.
phar/images/wow.jpg');
17. $> phar help-list
add compress delete extract help
help-list info list meta-del meta-get
meta-set pack sign stub-get
stub-set tree version
Debugging
18. Creating a Tar or Zip file
● Can be done with phar.readonly = 1
● Should not have a stub or alias
● Should use tar or zip extensions
19. <?php
$tar = new Phar($saveLoc, $flags, $alias, Phar::TAR);
$tar->compress(Phar::GZ)
$zip = new Phar($saveLoc, $flags, $alias, Phar::ZIP);
$zip->compress(Phar::BZ2)
Creating a Tar or Zip file
20. The box Project
● https://github.com/box-project/
● Framework for creating Phar files
● Lots of utility functions & classes for the
compiler script
● Not part of your project
● Box 3 has been in development for over a
year
21. A word on performance
● APC does not support PHAR
● Using the PHAR format is faster than Tar or
Zip
● Avoid compression if you’re going to use it
on the web
22. Resources
● PHP.net PHAR Manual
● Composer Compiler
● WebPhar Tutorial
● Working with .phar files
● Iterators in PHP - by Jake Smith @jakefolio
● Backup Project