Skip to content

Commit

Permalink
build/server-phar: compress using gzip (except stub)
Browse files Browse the repository at this point in the history
this produces a 75% reduction in phar size, at the expense of a slight degradation of autoloading speed and needing a writable tmpdir.
  • Loading branch information
dktapps committed Feb 2, 2020
1 parent 1f2fb73 commit 963abb7
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions build/server-phar.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,9 @@ function buildPhar(string $pharPath, string $basePath, array $includedPaths, arr
yield "Added $count files";

if($compression !== null){
yield "Checking for compressible files...";
foreach($phar as $file => $finfo){
/** @var \PharFileInfo $finfo */
if($finfo->getSize() > (1024 * 512)){
yield "Compressing " . $finfo->getFilename();
$finfo->compress($compression);
}
}
yield "Compressing files...";
$phar->compressFiles($compression);
yield "Finished compression";
}
$phar->stopBuffering();

Expand All @@ -137,7 +132,23 @@ function main() : void{
[
'git' => $gitHash
],
'<?php require("phar://" . __FILE__ . "/src/pocketmine/PocketMine.php"); __HALT_COMPILER();'
<<<'STUB'
<?php
$tmpDir = sys_get_temp_dir();
if(!is_readable($tmpDir) or !is_writable($tmpDir)){
echo "ERROR: tmpdir $tmpDir is not accessible." . PHP_EOL;
echo "Check that the directory exists, and that the current user has read/write permissions for it." . PHP_EOL;
echo "Alternatively, set 'sys_temp_dir' to a different directory in your php.ini file." . PHP_EOL;
exit(1);
}
require("phar://" . __FILE__ . "/src/pocketmine/PocketMine.php");
__HALT_COMPILER();
STUB
,
\Phar::SHA1,
\Phar::GZ
) as $line){
echo $line . PHP_EOL;
}
Expand Down

0 comments on commit 963abb7

Please sign in to comment.