startBuffering(); $directories = array( 'src', 'vendor', 'scripts' ); foreach ($directories as $dirname) { $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirname)); while ($iterator->valid()) { if ($iterator->isFile()) { $path = $iterator->getPathName(); if ('php' == strtolower($iterator->getExtension())) { $contents = php_strip_whitespace($path); $phar->addFromString($path, $contents); } else { $phar->addFile($path); } } $iterator->next(); } } $stub = "#!/usr/bin/env php\n" . $phar->createDefaultStub($scriptFilename); $phar->setStub($stub); $phar->compressFiles(Phar::GZ); $phar->stopBuffering(); rename($pharFilename, $binaryFilename); chmod($binaryFilename, 0775);