mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-19 05:14:52 +08:00
rename SPC_RETRY_TIME to SPC_DOWNLOAD_RETRIES to clear up what it's doing
sleep 5 seconds between retries
This commit is contained in:
parent
a7adec1341
commit
0b3421e3cd
@ -134,7 +134,7 @@ class DownloadCommand extends BaseCommand
|
|||||||
|
|
||||||
// retry
|
// retry
|
||||||
$retry = intval($this->getOption('retry'));
|
$retry = intval($this->getOption('retry'));
|
||||||
f_putenv('SPC_RETRY_TIME=' . $retry);
|
f_putenv('SPC_DOWNLOAD_RETRIES=' . $retry);
|
||||||
|
|
||||||
// Use shallow-clone can reduce git resource download
|
// Use shallow-clone can reduce git resource download
|
||||||
if ($this->getOption('shallow-clone')) {
|
if ($this->getOption('shallow-clone')) {
|
||||||
|
|||||||
@ -58,7 +58,7 @@ class SwitchPhpVersionCommand extends BaseCommand
|
|||||||
|
|
||||||
// retry
|
// retry
|
||||||
$retry = intval($this->getOption('retry'));
|
$retry = intval($this->getOption('retry'));
|
||||||
f_putenv('SPC_RETRY_TIME=' . $retry);
|
f_putenv('SPC_DOWNLOAD_RETRIES=' . $retry);
|
||||||
|
|
||||||
Downloader::downloadSource('php-src', Config::getSource('php-src'));
|
Downloader::downloadSource('php-src', Config::getSource('php-src'));
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,7 @@ class Downloader
|
|||||||
logger()->debug("finding {$name} source from bitbucket tag");
|
logger()->debug("finding {$name} source from bitbucket tag");
|
||||||
$data = json_decode(self::curlExec(
|
$data = json_decode(self::curlExec(
|
||||||
url: "https://api.bitbucket.org/2.0/repositories/{$source['repo']}/refs/tags",
|
url: "https://api.bitbucket.org/2.0/repositories/{$source['repo']}/refs/tags",
|
||||||
retry: self::getRetryTime()
|
retries: self::getRetryAttempts()
|
||||||
), true);
|
), true);
|
||||||
$ver = $data['values'][0]['name'];
|
$ver = $data['values'][0]['name'];
|
||||||
if (!$ver) {
|
if (!$ver) {
|
||||||
@ -39,7 +39,7 @@ class Downloader
|
|||||||
$headers = self::curlExec(
|
$headers = self::curlExec(
|
||||||
url: $url,
|
url: $url,
|
||||||
method: 'HEAD',
|
method: 'HEAD',
|
||||||
retry: self::getRetryTime()
|
retries: self::getRetryAttempts()
|
||||||
);
|
);
|
||||||
preg_match('/^content-disposition:\s+attachment;\s*filename=("?)(?<filename>.+\.tar\.gz)\1/im', $headers, $matches);
|
preg_match('/^content-disposition:\s+attachment;\s*filename=("?)(?<filename>.+\.tar\.gz)\1/im', $headers, $matches);
|
||||||
if ($matches) {
|
if ($matches) {
|
||||||
@ -67,7 +67,7 @@ class Downloader
|
|||||||
$data = json_decode(self::curlExec(
|
$data = json_decode(self::curlExec(
|
||||||
url: "https://api.github.com/repos/{$source['repo']}/{$type}",
|
url: "https://api.github.com/repos/{$source['repo']}/{$type}",
|
||||||
hooks: [[CurlHook::class, 'setupGithubToken']],
|
hooks: [[CurlHook::class, 'setupGithubToken']],
|
||||||
retry: self::getRetryTime()
|
retries: self::getRetryAttempts()
|
||||||
), true);
|
), true);
|
||||||
|
|
||||||
$url = null;
|
$url = null;
|
||||||
@ -91,7 +91,7 @@ class Downloader
|
|||||||
url: $url,
|
url: $url,
|
||||||
method: 'HEAD',
|
method: 'HEAD',
|
||||||
hooks: [[CurlHook::class, 'setupGithubToken']],
|
hooks: [[CurlHook::class, 'setupGithubToken']],
|
||||||
retry: self::getRetryTime()
|
retries: self::getRetryAttempts()
|
||||||
);
|
);
|
||||||
preg_match('/^content-disposition:\s+attachment;\s*filename=("?)(?<filename>.+\.tar\.gz)\1/im', $headers, $matches);
|
preg_match('/^content-disposition:\s+attachment;\s*filename=("?)(?<filename>.+\.tar\.gz)\1/im', $headers, $matches);
|
||||||
if ($matches) {
|
if ($matches) {
|
||||||
@ -118,7 +118,7 @@ class Downloader
|
|||||||
$data = json_decode(self::curlExec(
|
$data = json_decode(self::curlExec(
|
||||||
url: "https://api.github.com/repos/{$source['repo']}/releases",
|
url: "https://api.github.com/repos/{$source['repo']}/releases",
|
||||||
hooks: [[CurlHook::class, 'setupGithubToken']],
|
hooks: [[CurlHook::class, 'setupGithubToken']],
|
||||||
retry: self::getRetryTime()
|
retries: self::getRetryAttempts()
|
||||||
), true);
|
), true);
|
||||||
$url = null;
|
$url = null;
|
||||||
foreach ($data as $release) {
|
foreach ($data as $release) {
|
||||||
@ -156,7 +156,7 @@ class Downloader
|
|||||||
public static function getFromFileList(string $name, array $source): array
|
public static function getFromFileList(string $name, array $source): array
|
||||||
{
|
{
|
||||||
logger()->debug("finding {$name} source from file list");
|
logger()->debug("finding {$name} source from file list");
|
||||||
$page = self::curlExec($source['url'], retry: self::getRetryTime());
|
$page = self::curlExec($source['url'], retries: self::getRetryAttempts());
|
||||||
preg_match_all($source['regex'], $page, $matches);
|
preg_match_all($source['regex'], $page, $matches);
|
||||||
if (!$matches) {
|
if (!$matches) {
|
||||||
throw new DownloaderException("Failed to get {$name} version");
|
throw new DownloaderException("Failed to get {$name} version");
|
||||||
@ -201,7 +201,7 @@ class Downloader
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
self::registerCancelEvent($cancel_func);
|
self::registerCancelEvent($cancel_func);
|
||||||
self::curlDown(url: $url, path: FileSystem::convertPath(DOWNLOAD_PATH . "/{$filename}"), retry: self::getRetryTime());
|
self::curlDown(url: $url, path: FileSystem::convertPath(DOWNLOAD_PATH . "/{$filename}"), retry: self::getRetryAttempts());
|
||||||
self::unregisterCancelEvent();
|
self::unregisterCancelEvent();
|
||||||
logger()->debug("Locking {$filename}");
|
logger()->debug("Locking {$filename}");
|
||||||
if ($download_as === SPC_DOWNLOAD_PRE_BUILT) {
|
if ($download_as === SPC_DOWNLOAD_PRE_BUILT) {
|
||||||
@ -366,7 +366,7 @@ class Downloader
|
|||||||
$pkg['url'],
|
$pkg['url'],
|
||||||
$pkg['rev'],
|
$pkg['rev'],
|
||||||
$pkg['extract'] ?? null,
|
$pkg['extract'] ?? null,
|
||||||
self::getRetryTime(),
|
self::getRetryAttempts(),
|
||||||
SPC_DOWNLOAD_PRE_BUILT
|
SPC_DOWNLOAD_PRE_BUILT
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
@ -472,7 +472,7 @@ class Downloader
|
|||||||
$source['url'],
|
$source['url'],
|
||||||
$source['rev'],
|
$source['rev'],
|
||||||
$source['path'] ?? null,
|
$source['path'] ?? null,
|
||||||
self::getRetryTime(),
|
self::getRetryAttempts(),
|
||||||
$download_as
|
$download_as
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
@ -504,7 +504,7 @@ class Downloader
|
|||||||
*
|
*
|
||||||
* @throws DownloaderException
|
* @throws DownloaderException
|
||||||
*/
|
*/
|
||||||
public static function curlExec(string $url, string $method = 'GET', array $headers = [], array $hooks = [], int $retry = 0): string
|
public static function curlExec(string $url, string $method = 'GET', array $headers = [], array $hooks = [], int $retries = 0): string
|
||||||
{
|
{
|
||||||
foreach ($hooks as $hook) {
|
foreach ($hooks as $hook) {
|
||||||
$hook($method, $url, $headers);
|
$hook($method, $url, $headers);
|
||||||
@ -551,9 +551,10 @@ class Downloader
|
|||||||
}
|
}
|
||||||
return implode("\n", $output);
|
return implode("\n", $output);
|
||||||
} catch (DownloaderException $e) {
|
} catch (DownloaderException $e) {
|
||||||
if ($retry > 0) {
|
if ($retries > 0) {
|
||||||
logger()->notice('Retrying curl exec ...');
|
logger()->notice('Retrying curl exec after 5 seconds...');
|
||||||
return self::curlExec($url, $method, $headers, $hooks, $retry - 1);
|
sleep(5);
|
||||||
|
return self::curlExec($url, $method, $headers, $hooks, $retries - 1);
|
||||||
}
|
}
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
@ -628,9 +629,9 @@ class Downloader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function getRetryTime(): int
|
private static function getRetryAttempts(): int
|
||||||
{
|
{
|
||||||
return intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0);
|
return intval(getenv('SPC_DOWNLOAD_RETRIES') ?: 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -34,7 +34,7 @@ class PhpSource extends CustomSourceBase
|
|||||||
// 查找最新的小版本号
|
// 查找最新的小版本号
|
||||||
$info = json_decode(Downloader::curlExec(
|
$info = json_decode(Downloader::curlExec(
|
||||||
url: "https://www.php.net/releases/index.php?json&version={$major_version}",
|
url: "https://www.php.net/releases/index.php?json&version={$major_version}",
|
||||||
retry: intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0)
|
retries: intval(getenv('SPC_DOWNLOAD_RETRIES') ?: 0)
|
||||||
), true);
|
), true);
|
||||||
if (!isset($info['version'])) {
|
if (!isset($info['version'])) {
|
||||||
throw new DownloaderException("Version {$major_version} not found.");
|
throw new DownloaderException("Version {$major_version} not found.");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user