From 0d17bbc3969ce086cb273c91565081b4d9a6af08 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Wed, 4 Mar 2026 15:32:45 +0800 Subject: [PATCH 1/2] Use gnu mirror for gmp source --- config/source.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/source.json b/config/source.json index 114118bb4..040197cb1 100644 --- a/config/source.json +++ b/config/source.json @@ -361,7 +361,7 @@ }, "gmp": { "type": "filelist", - "url": "https://gmplib.org/download/gmp/", + "url": "https://ftp.gnu.org/gnu/gmp/", "regex": "/href=\"(?gmp-(?[^\"]+)\\.tar\\.xz)\"/", "provide-pre-built": true, "alt": { From 172bba871050de71b2ef03176f34ebb76e65518c Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Wed, 4 Mar 2026 15:33:05 +0800 Subject: [PATCH 2/2] Add php-src mirror --- src/SPC/store/source/PhpSource.php | 43 +++++++++++++++++++----------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/SPC/store/source/PhpSource.php b/src/SPC/store/source/PhpSource.php index 27e8bb891..02ba87554 100644 --- a/src/SPC/store/source/PhpSource.php +++ b/src/SPC/store/source/PhpSource.php @@ -6,11 +6,17 @@ use JetBrains\PhpStorm\ArrayShape; use SPC\exception\DownloaderException; +use SPC\exception\SPCException; use SPC\store\Downloader; class PhpSource extends CustomSourceBase { - public const NAME = 'php-src'; + public const string NAME = 'php-src'; + + public const array WEB_PHP_DOMAINS = [ + 'https://www.php.net', + 'https://phpmirror.static-php.dev', + ]; public function fetch(bool $force = false, ?array $config = null, int $lock_as = SPC_DOWNLOAD_SOURCE): void { @@ -28,21 +34,26 @@ public function fetch(bool $force = false, ?array $config = null, int $lock_as = #[ArrayShape(['type' => 'string', 'path' => 'string', 'rev' => 'string', 'url' => 'string'])] public function getLatestPHPInfo(string $major_version): array { - // 查找最新的小版本号 - $info = json_decode(Downloader::curlExec( - url: "https://www.php.net/releases/index.php?json&version={$major_version}", - retries: (int) getenv('SPC_DOWNLOAD_RETRIES') ?: 0 - ), true); - if (!isset($info['version'])) { - throw new DownloaderException("Version {$major_version} not found."); + foreach (self::WEB_PHP_DOMAINS as $domain) { + try { + $info = json_decode(Downloader::curlExec( + url: "{$domain}/releases/index.php?json&version={$major_version}", + retries: (int) getenv('SPC_DOWNLOAD_RETRIES') ?: 0 + ), true); + if (!isset($info['version'])) { + throw new DownloaderException("Version {$major_version} not found."); + } + $version = $info['version']; + return [ + 'type' => 'url', + 'url' => "{$domain}/distributions/php-{$version}.tar.xz", + ]; + } catch (SPCException) { + logger()->warning('Failed to fetch latest PHP version for major version {$major_version} from {$domain}, trying next mirror if available.'); + continue; + } } - - $version = $info['version']; - - // 从官网直接下载 - return [ - 'type' => 'url', - 'url' => "https://www.php.net/distributions/php-{$version}.tar.xz", - ]; + // exception if all mirrors failed + throw new DownloaderException("Failed to fetch latest PHP version for major version {$major_version} from all tried mirrors."); } }