For those who want the benefit of having a small compressed PHAR archive but don’t want to suffer the performance loss, use php_strip_whitespace when adding files to the archive. If your code has plenty of whitespace, docbocks, and single-line comments this function can greatly decrease archive size without the performance loss.
<?php
$sDir = 'application';
$oPhar = new Phar ('app.phar');
$oDir = new RecursiveIteratorIterator (new RecursiveDirectoryIterator ($sDir), RecursiveIteratorIterator::SELF_FIRST);
foreach ($oDir as $sFile) {
if ( preg_match ('/\\.php$/i', $sFile) ) {
$oPhar->addFromString (substr ($sFile, strlen ($sDir) + 1), php_strip_whitespace ($sFile));
}
}
?>