2009年9月13日星期日

Re: [fw-mvc] Serving static content to Anonymous user

Hi Raavi,

I have played around with something like this previously where by I cached my static pages and used Apache RewriteRules to use the cached page if the user was not logged in (i.e. they had no session cookie, as I didn't register a session for annonymous users).

Here is a snippet from my .htaccess file for an example:

    # Funky cache
    RewriteCond %{REQUEST_METHOD} !=POST
    RewriteCond %{HTTP:Accept-Encoding} gzip
    RewriteCond %{DOCUMENT_ROOT}/cache/$1/index.html.gz -f
    RewriteRule ^(.*) cache/$1/index.html.gz [L]
   
    RewriteCond %{REQUEST_METHOD} !=POST
    RewriteCond %{DOCUMENT_ROOT}/cache/$1/index.html -f
    RewriteRule ^(.*) cache/$1/index.html [L]
   
    # Rewrite everything else to the front-controller
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteRule .* index.php

I had a cache directory in public, which stores all my statically cached content. So if the page "controller/action" is requested then Apache will check if public/cache/controller/action/index.html exists, otherwise will it continue to pass the request to the Zend Framework application.

The benefit of this approach is that it is dramatically faster when you bypass PHP all the together. There is more too it than this ofcourse, you need a way of creating/clearing the static cache, etc, etc. But hopefully this gives you some ideas of what can be achieved.

Tom

2009/9/12 Raavi Raaj <raaviraaj77@gmail.com>
Hello,

I have a standard ZF (1.8.4) application setup, similar to the quickstart app.

The idea is to:
- Serve cached "page" for Anonymous users and
- Bybass the cache for signed in users.

Ideally where should I place the check for registered user, and start the page cache?

Will it help if I provided my index.php and bootstap.php code?

cheers,
-R

没有评论: