diff --git a/README-zh.md b/README-zh.md index 2a26b1565..11fbe4e65 100755 --- a/README-zh.md +++ b/README-zh.md @@ -43,9 +43,12 @@ static-php-cli(简称 `spc`)有许多特性: 如果你不想自行编译 PHP,可以从本项目现有的示例 Action 下载 Artifact,也可以从自托管的服务器下载。 -- [扩展组合 - common](https://dl.static-php.dev/static-php-cli/common/):common 组合包含了约 [30+](https://dl.static-php.dev/static-php-cli/common/README.txt) 个常用扩展,体积为 22MB 左右。 -- [扩展组合 - bulk](https://dl.static-php.dev/static-php-cli/bulk/):bulk 组合包含了 [50+](https://dl.static-php.dev/static-php-cli/bulk/README.txt) 个扩展,体积为 70MB 左右。 -- [扩展组合 - minimal](https://dl.static-php.dev/static-php-cli/minimal/):minimal 组合包含了 [5](https://dl.static-php.dev/static-php-cli/minimal/README.txt) 个扩展,体积为 6MB 左右。 +- [扩展组合 - common](https://dl.static-php.dev/static-php-cli/common/):common 组合包含了约 [30+](https://dl.static-php.dev/static-php-cli/common/README.txt) 个常用扩展,体积为 7.5MB 左右。 +- [扩展组合 - bulk](https://dl.static-php.dev/static-php-cli/bulk/):bulk 组合包含了 [50+](https://dl.static-php.dev/static-php-cli/bulk/README.txt) 个扩展,体积为 25MB 左右。 +- [扩展组合 - minimal](https://dl.static-php.dev/static-php-cli/minimal/):minimal 组合包含了 [5](https://dl.static-php.dev/static-php-cli/minimal/README.txt) 个扩展,体积为 3MB 左右。 + +> Linux 和 Windows 默认启用了 UPX 压缩,可减小 30~50% 的 PHP 二进制体积。 +> macOS 当前不支持 UPX,所以上述预编译的 macOS 版本体积可能较大。 对于 Windows 系统,目前支持的扩展较少,故仅提供 SPC 自身运行的最小扩展组合的 `cli` 和 `micro`:[扩展组合 - spc-min](https://dl.static-php.dev/static-php-cli/windows/spc-min/)。 diff --git a/README.md b/README.md index 7d423681b..91e8953c6 100755 --- a/README.md +++ b/README.md @@ -49,9 +49,12 @@ If you don't want to build or want to test first, you can download example pre-c Below are several precompiled static-php binaries with different extension combinations, which can be downloaded directly according to your needs. -- [Extension-Combination - common](https://dl.static-php.dev/static-php-cli/common/): `common` contains about [30+](https://dl.static-php.dev/static-php-cli/common/README.txt) commonly used extensions, and the size is about 22MB. -- [Extension-Combination - bulk](https://dl.static-php.dev/static-php-cli/bulk/): `bulk` contains [50+](https://dl.static-php.dev/static-php-cli/bulk/README.txt) extensions and is about 70MB in size. -- [Extension-Combination - minimal](https://dl.static-php.dev/static-php-cli/minimal/): `minimal` contains [5](https://dl.static-php.dev/static-php-cli/minimal/README.txt) extensions and is about 6MB in size. +- [Extension-Combination - common](https://dl.static-php.dev/static-php-cli/common/): `common` contains about [30+](https://dl.static-php.dev/static-php-cli/common/README.txt) commonly used extensions, and the size is about 7.5MB. +- [Extension-Combination - bulk](https://dl.static-php.dev/static-php-cli/bulk/): `bulk` contains [50+](https://dl.static-php.dev/static-php-cli/bulk/README.txt) extensions and is about 25MB in size. +- [Extension-Combination - minimal](https://dl.static-php.dev/static-php-cli/minimal/): `minimal` contains [5](https://dl.static-php.dev/static-php-cli/minimal/README.txt) extensions and is about 3MB in size. + +> Linux and Windows supports UPX compression for binaries, which can reduce the size of the binary by 30% to 50%. +> macOS does not support UPX compression, so the size of the pre-built binaries for mac is larger. For Windows systems, there are currently fewer extensions supported, so only `cli` and `micro` that run the minimum extension combination of SPC itself are provided: [Extension-Combination - spc-min](https://dl.static-php.dev/static-php-cli/windows/spc-min/). diff --git a/src/SPC/command/SwitchPhpVersionCommand.php b/src/SPC/command/SwitchPhpVersionCommand.php new file mode 100644 index 000000000..ac5ae01fa --- /dev/null +++ b/src/SPC/command/SwitchPhpVersionCommand.php @@ -0,0 +1,67 @@ +addArgument( + 'php-major-version', + InputArgument::REQUIRED, + 'PHP major version (supported: 7.4, 8.0, 8.1, 8.2, 8.3)', + null, + fn () => ['7.4', '8.0', '8.1', '8.2', '8.3'] + ); + $this->no_motd = true; + + $this->addOption('retry', 'R', InputOption::VALUE_REQUIRED, 'Set retry time when downloading failed (default: 0)', '0'); + } + + public function handle(): int + { + $php_ver = $this->input->getArgument('php-major-version'); + if (!in_array($php_ver, ['7.4', '8.0', '8.1', '8.2', '8.3'])) { + $this->output->writeln('Invalid PHP major version ' . $php_ver . ' !'); + return static::FAILURE; + } + + // detect if downloads/.lock.json exists + $lock_file = DOWNLOAD_PATH . '/.lock.json'; + // parse php-src part of lock file + $lock_data = json_decode(file_get_contents($lock_file), true); + // get php-src downloaded file name + $php_src = $lock_data['php-src']; + $file = DOWNLOAD_PATH . '/' . ($php_src['filename'] ?? '.donot.delete.me'); + if (file_exists($file)) { + $this->output->writeln('Removing old PHP source...'); + unlink($file); + } + + // Download new PHP source + $this->output->writeln('Downloading PHP source...'); + define('SPC_BUILD_PHP_VERSION', $php_ver); + + // retry + $retry = intval($this->getOption('retry')); + f_putenv('SPC_RETRY_TIME=' . $retry); + + Downloader::downloadSource('php-src', Config::getSource('php-src')); + + // Remove source/php-src dir + FileSystem::removeDir(SOURCE_PATH . '/php-src'); + + $this->output->writeln('Switched to PHP ' . $php_ver . ' successfully!'); + return static::SUCCESS; + } +}