From e78a01e9cb86f665d4986c05d8d06e4657015fe8 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 5 Nov 2017 05:20:48 +0000 Subject: mirror: handle network issues --- mirror.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mirror.php b/mirror.php index ff463f4..8a61747 100644 --- a/mirror.php +++ b/mirror.php @@ -8,6 +8,7 @@ $_SERVER["SCRIPT_NAME"] = '/.fancyindex/mirror.php'; // Configuration +ini_set('default_socket_timeout', 2); $tier0_url = 'https://repo.parabola.nu'; $mirrors_urls = [ 'https://www.parabola.nu/mirrors/status/tier/1/json' //, 'https://www.parabola.nu/mirrors/status/tier/2/json' @@ -40,7 +41,16 @@ if (!file_exists($root.'/'.$filename)) { // TODO: weight by GeoIP or quality or something? $mirrors = array(); foreach ($mirrors_urls as $mirrors_url) { - $json = json_decode(file_get_contents($mirrors_url), true); + $str = file_get_contents($mirrors_url); + if ($str === false) { + error_log("REPOMIRROR Warning: read: ".$mirrors_url); + continue; + } + $json = json_decode($str, true); + if ($json === NULL) { + error_log("REPOMIRROR Warning: decode: ".$mirrors_url); + continue; + } foreach ($json['urls'] as $urldata) { if (!in_array($urldata['protocol'], ['http', 'https', 'ftp'])) { continue; } if (strtotime($urldata['last_sync']) < $ctime) { continue; } -- cgit v1.2.2