From 5754acee1899ef88b40e5d7787f28d8b4865fbc9 Mon Sep 17 00:00:00 2001
From: Garreau Alexandre
Date: Mon, 14 Oct 2013 20:11:42 +0200
Subject: [PATCH 1/3] =?UTF-8?q?Ajout=20d=E2=80=99un=20cache?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Ajout d’un système de cache de la génération de l’index des documents comme de la liste d’autoblog stockés respectivement dans `/docs.cache` et `/autoblogs.cache`. La durée est paramétrable avec les variables `DOCS_CACHE_DURATION` et `AUTOBLOGS_CACHE_DURATION`, à ajouter dans `config.php.example`.
Merci au Hollandais volant pour cette astuce qui réduit par trois le temps de génération du code d’`index.php` et considérablement la charge processeur ;) .
---
index.php | 165 +++++++++++++++++++++++++++++++++++-------------------
1 file changed, 106 insertions(+), 59 deletions(-)
diff --git a/index.php b/index.php
index 0502400..d2a574d 100644
--- a/index.php
+++ b/index.php
@@ -209,7 +209,7 @@ function svg_status($fill, $text, $back)
$svg_ok=svg_status('#008000', 'ok', '');
$svg_mv=svg_status('#0000ff', 'mv', ' ');
$svg_err=svg_status('#000000', 'err', ' ');
-
+
$errorlog="./".escape( $_GET['check'] ) ."/error.log";
$oldvalue = null;
@@ -265,8 +265,8 @@ if (isset($_GET['export'])) {
foreach($subdirs as $unit) {
if(is_dir($unit)) {
- $unit=substr($unit, 2);
$ini = parse_ini_file($unit.'/vvb.ini');
+ $unit=substr($unit, 2);
$config = new stdClass;
foreach ($ini as $key=>$value) {
@@ -331,7 +331,7 @@ if (isset($_GET['exportopml'])) // OPML
foreach($subdirs as $unit) {
if(is_dir($unit)) {
- $unit=substr($unit, 2);
+ $unit=substr($unit, 2);
$ini = parse_ini_file($unit.'/vvb.ini');
$config = new stdClass;
@@ -366,7 +366,7 @@ if (isset($_GET['sitemap']))
$subdirs = glob(AUTOBLOGS_FOLDER . "*");
foreach($subdirs as $unit) {
if(is_dir($unit)) {
- $unit=substr($unit, 2);
+ $unit=substr($unit, 2);
echo "\n ".$proto.$_SERVER['SERVER_NAME'].substr($_SERVER['PHP_SELF'], 0, -9)."$unit/"." \n";
echo ' '.date('c', filemtime($unit))." \n";
echo " hourly \n \n\n";
@@ -825,7 +825,7 @@ if( !empty($_POST['opml_file']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY
-
-
-
-
- '. substr($unit, (strrpos($unit, '/')) + 1 ) .'', $size);
}
}
- }
- if(!empty( $docs )) {
- echo '
+ if(!empty( $docs )) {
+ echo '
'."\n";
- foreach( $docs as $value ) {
- $str = $value[0];
- if ( !empty($value[1]) ) {
- $str = sprintf('%s (%s)', $value[0], $value[1]);
+
+ foreach( $docs as $value ) {
+ $str = $value[0];
+ if ( !empty($value[1]) ) {
+ $str = sprintf('%s (%s)', $value[0], $value[1]);
+ }
+ echo ' '. $str . " \n";
}
- echo ' '. $str . " \n";
- }
- echo '
+
+ echo '
'."\n";
+ }
+ }
+ // on recuperre le contenu du buffer
+ $contenuCache = ob_get_contents();
+ ob_end_flush(); // on termine la bufferisation
+ $fd = fopen("$fichierCache", "w"); // on ouvre le fichier cache
+ if ($fd) {
+ fwrite($fd,$contenuCache); // on écrit le contenu du buffer dans le fichier cache
+ fclose($fd);
}
+ // sinon le fichier cache existe déjà, on ne génère pas la page
+ // et on envoie le fichier statique à la place
+ } else {
+ readfile($fichierCache); // affichage du contenu du fichier
+ echo ' '."\n"; // et un petit message
+ }
?>
@@ -909,37 +931,44 @@ if( !empty($_POST['opml_file']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY
exportOPML
-
- $value) {
- $key = strtolower($key);
- $config->$key = $value;
+
+ ';
+ $subdirs = glob(AUTOBLOGS_FOLDER . "*");
+ $autoblogs = array();
+ foreach($subdirs as $unit) {
+ if(is_dir($unit)) {
+ if( !file_exists(ROOT_DIR . '/' . $unit . '/.disabled')) {
+ if( file_exists(ROOT_DIR . '/' . $unit . '/vvb.ini')) {
+ $ini = parse_ini_file(ROOT_DIR . '/' . $unit . '/vvb.ini');
+ if($ini) {
+ $config = new stdClass;
+ foreach ($ini as $key=>$value) {
+ $key = strtolower($key);
+ $config->$key = $value;
+ }
+ $autoblogs[$unit] = $config;
+ unset($ini);
}
- $autoblogs[$unit] = $config;
- unset($ini);
}
}
}
}
- }
-
- uasort($autoblogs, "objectCmp");
- $autoblogs_display = '';
-
- if(!empty($autoblogs)){
- foreach ($autoblogs as $key => $autoblog) {
- $opml_link='opml ';
- $autoblogs_display .= '
+
+ uasort($autoblogs, "objectCmp");
+ $autoblogs_display = '';
+
+ if(!empty($autoblogs)){
+ foreach ($autoblogs as $key => $autoblog) {
+ $opml_link='opml ';
+ $autoblogs_display .= '
';
- }
- }
- echo $autoblogs_display;
- ?>
-
- ".count($autoblogs)." autoblogs hébergés
"; ?>
+ }
+ }
+ echo $autoblogs_display;
+
+ echo '
+
+ '.count($autoblogs).' autoblogs hébergés
';
+
+ // on recuperre le contenu du buffer
+ $contenuCache = ob_get_contents();
+ ob_end_flush(); // on termine la bufferisation
+ $fd = fopen("$fichierCache", "w"); // on ouvre le fichier cache
+ if ($fd) {
+ fwrite($fd,$contenuCache); // on écrit le contenu du buffer dans le fichier cache
+ fclose($fd);
+ }
+ // sinon le fichier cache existe déjà, on ne génère pas la page
+ // et on envoie le fichier statique à la place
+ } else {
+ echo ''."\n".' '; // un message de début
+ readfile($fichierCache); // affichage du contenu du fichier
+ echo "\n".' '."\n"; // et un petit message
+ }
+ ?>
From dd931b07ffe9213f3f893fed825be6de508d9b46 Mon Sep 17 00:00:00 2001
From: Garreau Alexandre
Date: Thu, 24 Oct 2013 01:28:13 +0200
Subject: [PATCH 2/3] Update functions.php
---
functions.php | 3 +++
1 file changed, 3 insertions(+)
diff --git a/functions.php b/functions.php
index 6a6859c..875e980 100755
--- a/functions.php
+++ b/functions.php
@@ -16,6 +16,9 @@ if (!defined('FOLDER_MAX_LENGTH')) define('FOLDER_MAX_LENGTH', 80);
date_default_timezone_set('Europe/Paris');
setlocale(LC_TIME, 'fr_FR.UTF-8', 'fr_FR', 'fr');
+if( !defined('DOCS_CACHE_DURATION')) define( 'DOCS_CACHE_DURATION', 1800 );
+if( !defined('AUTOBLOGS_CACHE_DURATION')) define( 'AUTOBLOGS_CACHE_DURATION', 1800 );
+
if( !defined('ALLOW_FULL_UPDATE')) define( 'ALLOW_FULL_UPDATE', TRUE );
if( !defined('ALLOW_CHECK_UPDATE')) define( 'ALLOW_CHECK_UPDATE', TRUE );
From 949dd8fbee9416e1621c4c61c68e98558d7b417e Mon Sep 17 00:00:00 2001
From: Garreau Alexandre
Date: Thu, 24 Oct 2013 01:29:12 +0200
Subject: [PATCH 3/3] Update config.php.example
---
config.php.example | 3 +++
1 file changed, 3 insertions(+)
diff --git a/config.php.example b/config.php.example
index 1c884e9..acc54e3 100644
--- a/config.php.example
+++ b/config.php.example
@@ -13,6 +13,9 @@
// define( 'HEAD_TITLE', '');
// define( 'FOOTER', 'D\'après les premières versions de SebSauvage et Bohwaz .');
+// define( 'DOCS_CACHE_DURATION', 1800);
+// define( 'AUTOBLOGS_CACHE_DURATION', 1800);
+
// define( 'ALLOW_FULL_UPDATE', TRUE );
// define( 'ALLOW_CHECK_UPDATE', TRUE );