打包phar文件過大的問題。

根據一個開源工具獲得的靈感,使用流打包,並使用token_get_all移除了所用PHP文件的空白。如今打包出來只有93k了。謝謝關注。php

我一個簡單的文件,加上一個symfony的process包,打包出來竟有125M之巨,而composer那麼多文件打包出來只有1.6M,百思不得其解。附上打包代碼:html

<?php

$pharFilename = 'deploy.phar';

if (file_exists($pharFilename)) {
    e('remove old file...');
    unlink($pharFilename);
}

$ignoreFiles = [
    'readme.md',
    'composer.json',
    'composer.lock',
    '.gitignore',
    basename(__FILE__),
];

e('putting files...');

try {
    $phar = new Phar(
        __DIR__.DIRECTORY_SEPARATOR.$pharFilename,
        FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME,
        $pharFilename
    );
} catch (UnexpectedValueException $e) {
    echo $e->getMessage(), PHP_EOL;
} catch (BadMethodCallException $e) {
    echo $e->getMessage(), PHP_EOL;
}

e('building...');
$phar->buildFromDirectory(__DIR__);

e('remove unused files...');
array_walk($ignoreFiles, function ($file) use ($phar) {
    $phar->delete($file);
});

e('set stub...');
$phar->setStub($phar->createDefaultStub('deploy.php', 'deploy.php'));

e('compress...');
$phar->compressFiles(Phar::BZ2);

e('build done.');

function e($string)
{
    echo $string, PHP_EOL;
}

打包phar文件過大的問題。 >> php

這個答案描述的挺清楚的:
http://www.goodpm.net/postreply/php/1010000007306359/打包phar文件過大的問題.html
相關文章
相關標籤/搜索