[RC] HTTP Guest Cache

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment!
Ideas Centre
Haravikk
Registered User
Posts: 261
Joined: Sat Nov 02, 2002 4:42 pm

Re: [Beta] HTTP Guest Cache

Post by Haravikk »

Ah, I may already have fixed this issue in my v0.2.1, but I'll have to verify when I have time. First of all I need to clean up my working environment; I think I now have three different phpBB installations with slightly different versions of my mod and your mod, which isn't helping ;)
Haravikk
Registered User
Posts: 261
Joined: Sat Nov 02, 2002 4:42 pm

Re: [Beta] HTTP Guest Cache

Post by Haravikk »

Actually, although you're right that I should really be adding the parameter directly during redirects, I'm unsure of what exactly you're doing in your append_sid() hook that is preventing the function from continuing? If all you're doing is making sure that no SID is actually added to a URL then you ought to be able to do this by simply doing:

Code: Select all

$SID = '?sid=';
$user->session_id = $_SID = '';
You can do this in a hook by simply changing those values and then returning nothing (which allows the normal append_sid() function to execute normally, or you could set those values somewhere further up in the script's execution; basically anywhere after the line $user->session_begin() on support scripts, which would remove the need for a hook entirely. I've done it in my mod using my clear_session() method).

Anyway, it shouldn't matter much as I actually think I may be able to handle append_sid more cleanly in my own mod by adding "cache=1" via the $_EXTRA_URL array, which should be much easier for my mod overall, and should work fine with your hook as long as it appends $_EXTRA_URL values.
User avatar
Kot Matroskin
Registered User
Posts: 126
Joined: Sat May 29, 2010 9:44 am
Location: Minsk, Belarus
Name: Vitaly Filatenko
Contact:

Re: [Beta] HTTP Guest Cache

Post by Kot Matroskin »

I think modifying $SID and $_SID is better than returning whole string. I'll change it after mod validation finishing.
Haravikk
Registered User
Posts: 261
Joined: Sat Nov 02, 2002 4:42 pm

Re: [Beta] HTTP Guest Cache

Post by Haravikk »

I've updated the first post with the link to v0.2.1. I'm pretty sure I've probably missed some notes from the change log, but the major change is that the mod now uses $_EXTRA_URL to add its parameter, and has a routine for stripping parameters from links that shouldn't have them (most notably redirects during login). This also greatly simplifies changes to the append_sid() function (only a single block is inserted, no fiddly in-line additions).

It also adds an option that allows you to omit the no-cache="set-cookie"; this is required by caches such as CloudFlare that don't actually process the contents of a no-cache directive, and instead simply assume a resource is uncacheable if any form of no-cache directive is present. By default the directive is included, and should only be omitted if you know a caching service will strip the cookies for you anyway, which CloudFlare does do.

I've also tweaked how I omit cron-tasks; basically if headers are already sent then I do what I was doing before and prevent cron-jobs from being processed at all, however, if no headers were sent then I wait until cron-jobs have been processed, and if one is due then I unset my headers (prevent caching). This means that if a board receives only guest traffic (or the majority is guest traffic) then jobs will execute from every so often.


Anyway, I'm marking this as a release candidate as it… well, is. I haven't submitted to the mod queue just yet, but I will if no major issues crop up.
User avatar
Kot Matroskin
Registered User
Posts: 126
Joined: Sat May 29, 2010 9:44 am
Location: Minsk, Belarus
Name: Vitaly Filatenko
Contact:

Re: [RC] HTTP Guest Cache

Post by Kot Matroskin »

Do you have MODX update from 0.2.0 within the archive? :)
Haravikk
Registered User
Posts: 261
Joined: Sat Nov 02, 2002 4:42 pm

Re: [RC] HTTP Guest Cache

Post by Haravikk »

Kot Matroskin wrote:Do you have MODX update from 0.2.0 within the archive? :)
No, I haven't been bothering since the mod's been in development, and I've made more than enough copy/paste mistakes just with a single install file :D

Are there any tools for doing it automatically? You can still get v0.2.0 here if you know how to run a simple comparison? Otherwise I can try to make update instructions if you want, but I'll need to do it sometime later tomorrow, as I don't remember everything I've changed. It should all be restricted to functions.php though, everything else should just be replacing the files in include/ and language/ as nothing's changed for styles.
Last edited by Haravikk on Fri Mar 22, 2013 11:58 am, edited 1 time in total.
User avatar
Kot Matroskin
Registered User
Posts: 126
Joined: Sat May 29, 2010 9:44 am
Location: Minsk, Belarus
Name: Vitaly Filatenko
Contact:

Re: [RC] HTTP Guest Cache

Post by Kot Matroskin »

There are MODX Creator tool and MODX generator. https://www.phpbb.com/mods/modx-tools/

First I used MODX generator, then uploaded generated xml file to MODX creator.
User avatar
Pthelovod
Registered User
Posts: 106
Joined: Mon Feb 22, 2010 1:32 am
Location: Россия
Name: Alexs Pthelovod
Contact:

Re: [RC] HTTP Guest Cache

Post by Pthelovod »

Http Guest Cache v0.2.1 language ru Pthelovod :oops:

Code: Select all

<?php
/* BEGIN mod_http_guest_cache */
/**
*
* @package phpBB Guest Cache Russian Pthelovod 2013
* @copyright (c) 2013 Haravikk (haravikk.com)
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* DO NOT CHANGE
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

if (empty($lang) || !is_array($lang))
{
	$lang = array();
}

// DEVELOPERS PLEASE NOTE
//
// All language files should use UTF-8 as their encoding and the files must not contain a BOM.
//
// Placeholders can now contain order information, e.g. instead of
// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows
// translators to re-order the output of data while ensuring it remains correct
//
// You do not need this where single placeholders are used, e.g. 'Message %d' is fine
// equally where a string contains only two placeholders which are used to wrap text
// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine

$lang = array_merge($lang, array(
	// Compatibility
	'CGP_CAT_NAME'					    	  	    => 'Кеш страницы',

	// ACP Module
	'ACP_MOD_HTTP_GUEST_CACHE'		        		=> 'HTTP кеш Гостям',
	'ACP_MOD_HTTP_GUEST_CACHE_EXP'	         		=> 'Включение и настройка Промежуточного HTTP Кеширования страниц Гостям. Настройки действуют при правах запрещающих написание ответов и создания тем гостями. <strong>Важно</strong>: для проверки изменений для гостей при установке различных модов данную опцию необходимо отключать для того, что бы появилась возможность отслеживать изменения от установленных новых модов.',
	
	// ACP Settings
	'ACP_MOD_HTTP_GUEST_CACHE_GENERAL_INFO'         => 'Основные настройки',
	'ACP_MOD_HTTP_GUEST_CACHE_ENABLE'	         	=> 'Включить HTTP кеш Гостям',
	'ACP_MOD_HTTP_GUEST_CACHE_PARAM'	        	=> 'Путь к папке кеша',
	'ACP_MOD_HTTP_GUEST_CACHE_PARAM_EXP'        	=> 'Указать путь в папке кеша форума (cache) относительно корневой папки форума.',
	'ACP_MOD_HTTP_GUEST_CACHE_TIME'	        		=> 'Интервал времени',
	'ACP_MOD_HTTP_GUEST_CACHE_TIME_EXP'	        	=> 'Интервал времени для сохранения Промежуточных Кешированных страниц в минутах. Минимальное время минута, но возрастает нагрузка на ресурсы сервера. Максимально значение - 999 минут. По умолчанию стоит 15 минут.',
	
	// ACP Features
	'ACP_MOD_HTTP_GUEST_CACHE_FEATURES_INFO'        => 'Особенности',
	'ACP_MOD_HTTP_GUEST_CACHE_SEARCH'	        	=> 'Включение HTTP кеша в search.php',
	'ACP_MOD_HTTP_GUEST_CACHE_JSTIME'	        	=> 'Показ времени через Javascript',
	'ACP_MOD_HTTP_GUEST_CACHE_JSTIME_EXP'       	=> 'Данная настройка позволяет заменять действительное время на форуме через Javascript на время создания файлов Промежуточного Кеша. Действительное время будет заменено на время создания Промежуточых Кешированых страниц для всех пользователей, независимо от прав. При отключении данной опции время будет отображаться в соответствии с настройками каждого пользователя. <strong>Важно</strong>: при отсутствии поддержки Javascript в браузерах пользователей время страниц будет выводиться в соответствии с настройками сервера и личных настроек каждого.',
	'ACP_MOD_HTTP_GUEST_CACHE_SET_COOKIE'       	=> 'Игнорировать директиву no-cache="set-cookie".',
	'ACP_MOD_HTTP_GUEST_CACHE_SET_COOKIE_EXP'    	=> 'Некоторые HTTP кеши не обрабатывают "no-cache" в заголовках и просто трактуют любое значение как некешируемое. В этом случае Вы можете пропускать этот заголовок для совместимости.',
	
	// Load Settings
	'ACP_MOD_HTTP_GUEST_CACHE_LOAD_INFO'        	=> 'Слежение за Маркировкой',
	'ACP_MOD_HTTP_GUEST_CACHE_MARK'		        	=> 'Слежение за Использованием Маркировки тем и сообщений для гостей',
	'ACP_MOD_HTTP_GUEST_CACHE_MARK_EXP'	        	=> 'Включение слежения за Маркировкой тем для гостей требует использование дополнительных мощностей сервера и предотвращает быстрое HTTP кеширование главной, списков форумов и тем. Рекомендуется не использовать слежение за Маркировкой тем для гостей.',
	
	// Logs
	'LOG_MOD_HTTP_GUEST_CACHE_CONFIG'	        	=> '<strong>Изменены настройки HTTP кеш Гостей</strong><br />&raquo; %s',
	
	/**
	* A copy of Handyman` s MOD version check, to view it on the portal overview
	*/
	'ANNOUNCEMENT_TOPIC'	=> 'Сообщение о новом выпуске',
	'CURRENT_VERSION'		=> 'Текущая версия',
	'DOWNLOAD_LATEST'		=> 'Обновление текущей версии',
	'LATEST_VERSION'		=> 'Последняя версия',
	'NO_INFO'				=> 'Не удалось связаться с сервером для определения имеющейся новой версии',
	'NOT_UP_TO_DATE'		=> '%s не по дате',
	'RELEASE_ANNOUNCEMENT'	=> 'Важное сообщение',
	'UP_TO_DATE'			=> '%s на текущее время',
	'VERSION_CHECK'			=> 'MOD Проверка версии',
));
Peter77sx
Registered User
Posts: 3260
Joined: Wed Nov 09, 2005 2:51 pm

Re: [RC] HTTP Guest Cache

Post by Peter77sx »

Hello, testing this out along with CF and kot's MOD and so far it is working great.
Just a bit of a problem with mod rewrite when the MOD is activated...

For example in my .htaccess I am using
DirectoryIndex home.php index.php index.html index.htm

Navigating within forum any link back to 'home' shows site.com/?cache=1 and that's ok. but if I type and enter site.com directly from browser, it shows up as site.com/home.php?cache1

Any idea why that is happening?
I have tried moving the code around like before the page header is called and still same behavior.





Thanks
Haravikk
Registered User
Posts: 261
Joined: Sat Nov 02, 2002 4:42 pm

Re: [RC] HTTP Guest Cache

Post by Haravikk »

Well the reason it does this is that in each case it's building the URL via different means. All internal URLs on your board pass through the append_sid function, and if you are viewing a cacheable page then my mod ensures that the cache parameter is added by this function so that all pages you visit are also pulled from caches (if possible).

In other cases, namely when the user accesses your board from an external link, or via a non-cacheable page, then they will initially be viewing a URL without the cache parameter attached. In this case if the page is later determined to be cacheable then the script tries to get the current URL, and add the parameter to that. It gets the current URL using a phpBB function which seems to include the actual script name of the page, rather than the exact URL as entered by the user.


Hmm, I don't think the phpBB extract_current_page() function gives the format I would need, but PHP itself I believe stores the actual request URI somewhere which might let me cheat and use the location as it appeared in the browser. I'll try to get it into the release version.
Peter77sx
Registered User
Posts: 3260
Joined: Wed Nov 09, 2005 2:51 pm

Re: [RC] HTTP Guest Cache

Post by Peter77sx »

Thanks for the explanation I appreciate it. I have to pause testing a bit and was wondering if you could also shed a bit of light on my next issue. Not related to your mod, could you help me with using original phpbb IP to replace the one that is given by CF?

I looked at this
https://support.cloudflare.com/entries/ ... ith-PHPBB-
even though that line to find is outdated, I replaced it and still having trouble.
Session IP/browser/X_FORWARDED_FOR check failed
»User IP “108.162.217” checked against session IP “108.162.216”, user browser string “” checked against session browser string “” and user X_FORWARDED_FOR string “” checked against session X_FORWARDED_FOR string “”.
The ip' of course is cloudflare but I'm thinking it would probably be best to use phpbb3's user IP? that error happens when I go to my home.php and gives me a cached logged out version of the page( am I right?) since I am able to go back or click back to other pages and remain logged in.. this is with or without your MOD edit to my custom page.

Thanks again
Haravikk
Registered User
Posts: 261
Joined: Sat Nov 02, 2002 4:42 pm

Re: [RC] HTTP Guest Cache

Post by Haravikk »

I'm not sure you need to do this? My site uses CloudFlare but I still see the correct IP addresses if I look at post info (the question mark in a triangle icon on prosilver); CloudFlare should function as a transparent proxy in that the server shouldn't know it's there unless it specifically looks for CloudFlare specific headers.

Are you definitely receiving unexpected IP addresses? As I say I didn't have to change anything personally, I just activated CloudFlare and once the DNS changes went through it just worked. Only issue I had was that it wasn't caching pages, hence my need to create this mod :)
Peter77sx
Registered User
Posts: 3260
Joined: Wed Nov 09, 2005 2:51 pm

Re: [RC] HTTP Guest Cache

Post by Peter77sx »

Haravikk wrote:I'm not sure you need to do this? My site uses CloudFlare but I still see the correct IP addresses if I look at post info (the question mark in a triangle icon on prosilver); CloudFlare should function as a transparent proxy in that the server shouldn't know it's there unless it specifically looks for CloudFlare specific headers.

Are you definitely receiving unexpected IP addresses? As I say I didn't have to change anything personally, I just activated CloudFlare and once the DNS changes went through it just worked. Only issue I had was that it wasn't caching pages, hence my need to create this mod :)
My problem was that I had an additional rule set up that used a different pattern but was basically the same.


Anyway, I'll post the workaround I found doing a google search incase anyone runs into a simliar problem with member IP's being replaced by cloudflare.
Open includes/session.php Find:

Code: Select all

$this->ip = (!empty($_SERVER['REMOTE_ADDR'])) ? (string) $_SERVER['REMOTE_ADDR'] : ''; 
Replace with:

Code: Select all

$this->ip = (!empty($_SERVER['HTTP_CF_CONNECTING_IP']))
          ? (string) $_SERVER['HTTP_CF_CONNECTING_IP']
          : ((!empty($_SERVER['REMOTE_ADDR'])) ? (string) $_SERVER['REMOTE_ADDR'] : ''); 
source
SuperFedya
Registered User
Posts: 253
Joined: Sun Jul 14, 2002 9:14 pm
Contact:

Re: [RC] HTTP Guest Cache

Post by SuperFedya »

This mod works fine with Nginx server without Apache?

Thanks
Haravikk
Registered User
Posts: 261
Joined: Sat Nov 02, 2002 4:42 pm

Re: [RC] HTTP Guest Cache

Post by Haravikk »

SuperFedya wrote:This mod works fine with Nginx server without Apache?
I can't say for sure as I don't have nginx setup to test it, but I don't see any reason why it shouldn't work as the mod doesn't use any features that phpBB doesn't already require in order to run. So if you can run phpBB then this mod should work.
Locked

Return to “[3.0.x] MODs in Development”