Skip to content
This repository was archived by the owner on Jan 31, 2023. It is now read-only.

Commit 3cf0f67

Browse files
committed
More robust network error handling
1 parent b0a93f0 commit 3cf0f67

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/php/libsdk/SDK/Build/Dependency/Fetcher.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,23 @@ public function setSeries(Series $series) : void
3535

3636
/* TODO more robust implementation. */
3737
/* TODO implement indicator. */
38-
public function getByUri($uri) : string
38+
public function getByUri(string $uri, int $retries = 3) : string
3939
{/*{{{*/
4040
$url = "http://{$this->host}:{$this->port}$uri";
41+
$ret = false;
42+
43+
retry:
44+
try {
45+
$ret = $this->download($url);
46+
} catch (Exception $e) {
47+
if ($retries > 0) {
48+
sleep(1);
49+
$retries--;
50+
goto retry;
51+
}
52+
}
4153

42-
return $this->download($url);
54+
return $ret;
4355
}/*}}}*/
4456

4557
/*protected function fetch($uri) : string

lib/php/libsdk/SDK/FileOps.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,12 @@ protected function download(string $url, string $dest_fn = NULL) : ?string
135135
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
136136
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
137137
curl_setopt($ch, CURLOPT_USERAGENT, Config::getSdkUserAgentName());
138+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
138139

139140
$ret = curl_exec($ch);
140-
if (false === $ret) {
141+
142+
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
143+
if (false === $ret || 200 !== $code) {
141144
$err = curl_error($ch);
142145
curl_close($ch);
143146
if ($dest_fn) {

0 commit comments

Comments
 (0)