FORUMS CLOSED DUE TO SPAM. YOU STILL CAN ADD POST!

Funky Cache (beta testers wanted)

Feed 96 posts, 14 voices

Avatar
291 posts

Have you copy and pasted the mod_rewrite rules Funky Cache needs to .htaccess? You can find them from “Your .htaccess file”.

Maybe your system cannot create folders? Try to create one folder manually to check. For example if you have:

/foo.html
/foo/bar.html

And foo.html is what you describe as parent page and bar.html does not get cached. Then do the following:

cd /path/to/your/cache/folder
mkdir foo 
chmod a+w foo

Now request /foo/bar.html and see if it gets cached.

 
Avatar
184 posts

Manual folder creation works … seems your suspision that my system cannot create the folders is partly correct. The file manager plugin and other plugins I have tried can create folders fine, so I don’t think it is my ‘system’ but rather how Funky Cache creates them … any ideas why Funky cache’s method might be any different?

Debug is stating that the mkdir function has been passed an invalid argument on line 52. I assume that is because the expected $dir value is not being passed for some reason!?

If I trace the $dir value before that line, I notice something that is surely odd. The system path is preluded by a / character … in my case, I’m running the script on a Windows machine, thus this is an invalid value as nothing should prelude the drive letter in the path.

 
Avatar
184 posts

I removed the preluding / character from the $dir value on line 51 to get a proper path value, but no folder is created and now I get a file_put_contents warning on line 63.

I also wondered, is it normal behaviour for the cached pages to display just the doctype line in the html page before it is properly called upon?

 
Avatar
291 posts

Can you tell me what are your settings for the plugin? Also what operating system? What are the permissions for the cache folder?

Ah sorry did not read the previous one. I do not test for windows. Problems are most likely caused by my code using *NIX directory separator. Basically all instances of “/” should be “\” in Windows. Can be fixed by using DIRECTORY_SEPARATOR PHP constant. Will fix later when I come back from the holidays (next week).

 
Avatar
184 posts

I’m running Windows XP and all folders have full permissions on my machine.
Plugin settings are ‘Yes’ for cache by default, ‘.html’ for cache file suffix and ‘/cache/’ for cache folder.

 
Avatar
184 posts

System directory problem … definately. After you highlighted that I found a bunch of folders in the root of the drive that were definately attempts at creating the folders.

 
Avatar
541 posts

little suggestion for you tuupola

for the moment the easiest way to know if you are in backend or not is the check if FROG_VERSION is defined

if (defined('FROG_VERSION')) {
    /* backend stuff */
}
else {
    /* frontend stuff */
}

nice job by the way :) well coded

 
Avatar
76 posts

I’ve been working a bit on trying to get this plugin to work properly when you configure Frog without a page suffix.

The way I intend to do this is to create the folder structure, with an index.html page to hold the page content.

Example:

  • /articles/ -> /cache/articles/index.html
  • /projects/test/ -> /cache/projects/test/index.html

I started out doing this with a Frog setup in a subdirectory; but due to the way Apache/htaccess handles the REQUEST_URI/REQUEST_FILENAME – I don’t think it’s possible for it to distinguish between the directory that Frog is installed at and the URL of Frog’s page/subpage you want.

I have it slightly working – domain root (not subdirectory) with basic pages and no plugins. The code expects that there is no URL suffix – i.e. it is likely not to work with it set to .html.

Files

New models/FunkyCachePage.php

Link

Htaccess

# Rewrite to check for cached page.
#RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond %{DOCUMENT_ROOT}/cache/%{REQUEST_URI}/index.html -f
RewriteRule ^(.*)$ /cache/$1/index.html [L,QSA]

The above entries should go between Frog’s admin rule and the main Frog rule.

 
Avatar
541 posts

here is a other recommendation to make it more portable

in your model FunkyCachePage.php, replace the document_root to FROG_ROOT like this:

    public function path() {
        return FROG_ROOT . $this->url;
    }

EDIT: you like to complicate your life Craig ;)

    public function path() {
        $filename = $_SERVER['SCRIPT_FILENAME'];
        $filename = preg_replace('/admin\//', '', $filename);
        $filename = preg_replace('/index\.php$/', '', $filename);
        return $filename . $this->url;
    }
 
Avatar
76 posts

Hehe. Thanks philippe. Forgot about that ;)

 
Avatar
541 posts

:) your welcome

 
Avatar
291 posts

I’ve been working a bit on trying to get this plugin to work properly when you configure Frog without a page suffix.

You mean it is not working properly? What is the problem you are trying to solve?

 
Avatar
76 posts

@tuupola: Sorry; it does work! Because my Frog URL suffix was empty; I thought the Funky Cache plugin suffix also had to be empty – which didn’t work. An empty Frog suffix and a .html Funky Cache suffix works as expected :)

 
Avatar
184 posts

A suggestion for Funky Cache (in addition to supporting *nix and windows file systems) could be to have a trawling script to auto-regenerate flat html pages for all the pages. At present, if you change a page, the cached page will display blank on first visit until it is then viewed a second time (when the cached version will have then been created).

Obviously, for a large website, the webmaster would currently have a lengthy job of needing to re-visit all the pages to ensure that all pages are re-cached, so as to ensure visitors view the cached pages correctly on first visit.

 
Avatar
291 posts

At present, if you change a page, the cached page will display blank on first visit until it is then viewed a second time (when the cached version will have then been created).

Then there is something wrong with your system. Page should display just fine the first time it is requested. (Page displays just fine on all of my systems).

Obviously, for a large website, the webmaster would currently have a lengthy job of needing to re-visit all the pages to ensure that all pages are re-cached, so as to ensure visitors view the cached pages correctly on first visit.

If needed you can do it by issuing following command from shell:

wget -r -np http://www.example.com/

But as I said there is something broken in your system if first request gives you blank.

 
Avatar
184 posts

Hi Tuupola,

I’m thinking of running this on my live linux box to see if it works any differently to my local windows box. It is such a handy plugin, I think I need to give it some more time to do it justice.

I will post back if I have a different experience with it then.

 
Avatar
291 posts

I forgot you were running Windows. I do not test with it and it is quite possible my code has bugs in Windows. If you find a solution let me know and I will include the fix.

 
Avatar
184 posts

Hi Tuupola, I’ve been testing with our live servers and there is still definitely something wrong in caching child pages. I can still only cache parent pages.

Running Linux with PHP 5.2.10 and MySQL 5.0.81

 
Avatar
291 posts

BlueFrog: What are your Frog settings, Funky Cache settings and .htaccess file. Most likely there is something messed up in one of those.

 
Avatar
184 posts

Frog settings:

define(‘DEBUG’, false);
define(‘CHECK_UPDATES’, true);
define(‘CHECK_TIMEOUT’, 5);
define(‘URL_PUBLIC’, ‘http://frog.website.com/’);
define(‘ADMIN_DIR’, ‘admin’);
define(‘USE_MOD_REWRITE’, true);
define(‘URL_SUFFIX’, ‘.html’);
define(‘USE_PDO’, true);
define(‘DEFAULT_TIMEZONE’, ‘Europe/London’);

Funky cache settings:

Cach by default = yes
Cache file suffix = .html
Cache folder = /cache/
Cache folder permissions = 777

htaccess:

php_flag magic_quotes_gpc off
AddDefaultCharset UTF-8
Options -Indexes +FollowSymLinks
DirectoryIndex index.html index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^admin(.*)$ admin/index.php?$1 [L,QSA]
RewriteCond %{DOCUMENT_ROOT}/cache/index.html -f
RewriteRule ^$ /cache/index.html [L,QSA]
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond /cache/{REQUEST_URI} -f
RewriteRule ^(.*)$ /cache/$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?PAGE=$1 [L,QSA]
</IfModule>

As you can see, all defaults are set. Surely it must still be a problem in creating the folders … even on non-windows servers. I’ll switch debug on and see what I get.

 
Avatar
184 posts

Aha, debug is telling me that “open_basedir restriction in effect” … can this be overridden? or are we looking at potential hosting limitation with Funky Cache?

By the way, on a positive note, I no longer see blank pages when viewing the parent pages for the first time on this Linux server.

 
Avatar
291 posts

Check the PHP manual. I guess you can turn it off by adding the following to .htaccess (if your host allows that):

php_admin_value open_basedir none

Safe mode usually breaks lots of things. It will be removed in PHP 6.

 
Avatar
184 posts

That didn’t work for me, Tuupola.

I’m getting our server aadministrators to look into it for us and will hopefully have an update, as I am determined to ensure this things works.

 
Avatar
184 posts

I have the openbase restriction sorted, but there is still a problem making directories. I have also been advised not to use the script if it can’t work within openbase restrictions, for security reasons.

I personally think the directory creation method could do with a re-think, to ensure it can work across different servers. As it is something I am keen to see working, I will see if I can have a go at coming up with a working solution, perhaps one that works on a Windows server too.

 
Avatar
291 posts

Personally I have no interest in writing workarounds for PHP safe mode. Safe mode is known to cause all kind of problems, especially scripts which access the file system. After all that is one point of safe mode, to restrict what script can do. I vote with my wallet and never use any host which forces usage of safe mode.

That said, if you can find an easy solution and make a patch I will be happy to include it.