From 87bf9ce8cc959104241dbf591a29cb96ced19198 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 18 Mar 2021 20:33:44 +0100 Subject: index.php: cache news XML --- index.php | 77 +++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 45 insertions(+), 32 deletions(-) diff --git a/index.php b/index.php index e77e36e..7f5457a 100644 --- a/index.php +++ b/index.php @@ -73,25 +73,31 @@ print_header("", "home"); RSS Feed = 200 && $httpcode < 300 ) { - $news32 = simplexml_load_string($news32); +//apcu_clear_cache(); +$news32 = apcu_fetch('news32', $apcu_success); +if( $apcu_success == false ) { + $news32_reachable = apcu_fetch('news32_reachable', $apcu_success); + if ($apcu_success == false) { + if (site_is_reachable('https://bbs.archlinux32.org/extern.php?action=feed&fid=12&type=atom')) + $news32_reachable = 'YES'; + else + $news32_reachable = 'NO'; + apcu_store('news32_reachable', $news32_reachable, 300); + } + if ($news32_reachable == 'YES') { + $ch = curl_init('https://bbs.archlinux32.org/extern.php?action=feed&fid=12&type=atom'); + if( $ch != null && $ch != false ) { + 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); + $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + if( $httpcode >= 200 && $httpcode < 300 ) { + apcu_store('news32', $news32, 300); + } else { + $news32 = false; + } } else { $news32 = false; $news32status = "HTTP return code was $httpcode"; @@ -99,25 +105,32 @@ if ($news32_reachable == 'YES') { } else { $news = false; } -} else { - $news32 = false; +} +if( $news32 != false ) { + $news32 = simplexml_load_string($news32); } -$ch = curl_init("https://archlinux.org/feeds/news/"); -if( $ch != null && $ch != false ) { - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - $news64 = curl_exec($ch); - $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - curl_close($ch); - if( $httpcode >= 200 && $httpcode < 300 ) { - $news64 = simplexml_load_string($news64); +$news64 = apcu_fetch('news64', $apcu_success); +if( $apcu_success == false ) { + $ch = curl_init("https://archlinux.org/feeds/news/"); + if( $ch != null && $ch != false ) { + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + $news64 = curl_exec($ch); + $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + if( $httpcode >= 200 && $httpcode < 300 ) { + apcu_store('news64', $news64, 300); + } else { + $news64 = false; + } } else { $news64 = false; $news64status = "HTTP return code was $httpcode"; } -} else { - $news64 = false; +} +if( $news64 != false ) { + $news64 = simplexml_load_string($news64); } $news = array(); -- cgit v1.2.3-54-g00ecf