summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2019-10-31 20:39:40 +0100
committerErich Eckner <git@eckner.net>2019-10-31 20:40:17 +0100
commita674e136827d1d2a6459402ce634080011127ee7 (patch)
tree25149af5c1aacb7f99009ea43188e38b2e893b4c
parent580e190f5b2ee47178af454e638730ad98dea7d1 (diff)
downloadarchweb32-a674e136827d1d2a6459402ce634080011127ee7.tar.xz
index.php: do not fail if news.archlinux32.org is unavailable
-rw-r--r--index.php27
1 files changed, 20 insertions, 7 deletions
diff --git a/index.php b/index.php
index 2a3e937..d0e7334 100644
--- a/index.php
+++ b/index.php
@@ -4,6 +4,7 @@ require_once "init.php";
require_once BASE . "/lib/mysql.php";
require_once BASE . "/lib/style.php";
require_once BASE . "/lib/format.php";
+require_once BASE . "/lib/helper.php";
$result = mysql_run_query(
'SELECT `binary_packages`.`pkgname`,' .
@@ -72,13 +73,25 @@ print_header("", "home");
<a href="https://news.archlinux32.org/rss.php" title="Arch 32 News RSS Feed" class="rss-icon"><img width="16" height="16" src="/static/rss.c5ebdc5318d6.png" alt="RSS Feed" /></a>
<?php
-$ch = curl_init("https://news.archlinux32.org/rss.php");
-curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
-curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
-$news32 = curl_exec($ch);
-curl_close($ch);
-$news32 = simplexml_load_string($news32);
+$news_reachable = apcu_fetch('news_reachable', $apcu_success);
+if ($apcu_success == false) {
+ if (site_is_reachable('https://news.archlinux32.org/rss.php'))
+ $news_reachable = 'YES';
+ else
+ $news_reachable = 'NO';
+ apcu_store('news_reachable', $news_reachable, 300);
+}
+if ($news_reachable == 'YES') {
+ $ch = curl_init('https://news.archlinux32.org/rss.php');
+ curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
+ $news32 = curl_exec($ch);
+ curl_close($ch);
+ $news32 = simplexml_load_string($news32);
+} else {
+ $news32 = false;
+}
$ch = curl_init("https://www.archlinux.org/feeds/news/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);