Previous Next

Thread: Help with Output Caching and PHP

Last post 07-28-2008 4:33 PM by CarlosAg. 15 replies.

Average Rating Rate It (5)

RSS

Page 1 of 2 (16 items) 1 2 Next >

Sort Posts:

  • 07-19-2008, 4:32 AM

    • canadaka
    • Top 50 Contributor
    • Joined on 08-18-2006, 3:10 AM
    • Vancouver, Canada
    • Posts 63

    Help with Output Caching and PHP

    I am trying to enable Output caching for some PHP sites of mine, i tried following the guides on IIS.net but I can't seem to get any results.

    http://blogs.iis.net/bills/archive/2007/05/02/iis7-output-caching-for-dynamic-content-dramatically-speed-up-your-asp-and-php-applications.aspx

    http://blogs.iis.net/bills/archive/2006/10/31/PHP-on-IIS.aspx

    Wether I enable User-mod with * or kernal-mode, neither seems to work... I run "netsh http show cache" after and i always get "There were no cache entries corresponding to the provided URL".

    Seems i should get some sort of output like this?

    But when I run some WCAT tests it seems its working because me requests per second goes way up. So how can I make sure its working 100%?

    And with a PHP application like phpbb3, what would the best practice be? Enable user-mode with *, enable kernal mode. or enable user-mode with query variables like "t,f,p,start".

  • 07-19-2008, 4:57 AM In reply to

    • ksingla
    • Top 10 Contributor
    • Joined on 06-14-2006, 3:02 AM
    • Redmond, WA
    • Posts 561

    Re: Help with Output Caching and PHP

    "netsh http show cache" command only shows whats there in kernel mode cache. If your requests/sec went way up when you enabled user mode cache, user mode caching probably worked. Regarding comparison between *, specific querystring variables, kernel mode cache, if you want to ignore variation based on value of few querystring variables, you can use *. You should use specific query string variables in that case. If you want to vary by all query string variables, * is equally good. If your application satisfies these conditions and is fit for kernel response caching and your server sufficient resources to support kernel caching of all variations, kernel caching will always give you better performance.

  • 07-20-2008, 4:38 AM In reply to

    • canadaka
    • Top 50 Contributor
    • Joined on 08-18-2006, 3:10 AM
    • Vancouver, Canada
    • Posts 63

    Re: Help with Output Caching and PHP

    Seems Output caching doens't really work so well on a community site like forms, because it will cache the page as the user that requests it, so others will see the page as that user. Some of my forum members have reported to be logged into the site as another user, the welcome message lists another members name when it should list theres and so on.

    Its strange that i havn't witnessed this yet. But could there be a way to only 'output cache' pages to non logged in requests.

  • 07-20-2008, 5:10 AM In reply to

    • ksingla
    • Top 10 Contributor
    • Joined on 06-14-2006, 3:02 AM
    • Redmond, WA
    • Posts 561

    Re: Help with Output Caching and PHP

    There is no direct way to tell output caching module to not cache pages accessed by anonymous users. But you "can" enable output cache selectively for particular sites/apps using location tags. I understand you have already made decision as to what parts of your site require authentication and what not. With authentication settings in IIS configuration, you can selectively enable output caching for parts which don't require authentication.

    Also, output cache module in IIS supports caching multiple responses to same page based on query string variable values and http header values. So you can configure output caching module to cache a different response for each user. See if this can serve your needs.

    -Kanwal-

  • 07-20-2008, 8:02 PM In reply to

    • canadaka
    • Top 50 Contributor
    • Joined on 08-18-2006, 3:10 AM
    • Vancouver, Canada
    • Posts 63

    Re: Help with Output Caching and PHP

    hmm my entire site is within a CMS which has user authentication. Could one possibly set a custom http header through php when the request is not logged-in, then use the 'headers' option in the 'user-mode caching'?

  • 07-22-2008, 8:53 PM In reply to

    • ksingla
    • Top 10 Contributor
    • Joined on 06-14-2006, 3:02 AM
    • Redmond, WA
    • Posts 561

    Re: Help with Output Caching and PHP

    I am not familiar with PHP but you can probably figure out if user is anonymous and add a request header to indicate that but even then you cannot configure output caching to say only cache content which is server to anonymous users. If you would like output caching module to cache different responses for different users based on value of a particular request header value (set a custom header with value as username), that is possible.

  • 07-23-2008, 3:45 AM In reply to

    • canadaka
    • Top 50 Contributor
    • Joined on 08-18-2006, 3:10 AM
    • Vancouver, Canada
    • Posts 63

    Re: Help with Output Caching and PHP

    Hmm i'm trying to get it working with headers but it doens't seem to be working.

    I create a header in code named "Username" with the value of the current username or "anonymous" if none is specified. I used the developer toolbar to view the pages headers to verify that the custom header is being set, it is.

    Pages are being cached, but it doens't seem to cache seperate versions based on the "username" header. If I view a page as a guest, then view the same page in a different browser as a user, the page displayed is the guest cached apge, because it shows the login form.

    Here is the Output caching settings I have currently

    here are one of my pages headers viewed as a guest

    Content-Type: text/html
    Content-Encoding: gzip
    Vary: Accept-Encoding
    Server: Microsoft-IIS/7.0
    X-Powered-By: PHP/5.2.6
    Username: anonymous
    Date: Wed, 23 Jul 2008 07:45:08 GMT
    Content-Length: 7905
    
    200 OK
  • 07-23-2008, 1:24 PM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 6:13 PM
    • Redmond, WA
    • Posts 1,225

    Re: Help with Output Caching and PHP

    First of all, output-caching can vary by request headers/not response headers.  Also, adding header from your php app will not work since it is too late - the output cache lookup has already happened at this point - the best way to do this would be the following native module sample

    class CMyModule : CHttpModule
    {
        REQUEST_NOTIFICATION_STATUS
        OnPostAuthenticateRequest(
            IHttpContext *       pHttpContext,
            IHttpEventProvider * pEventProvider
        )
        {
            pHttpContext->GetResponse()->GetCachePolicy()->SetVaryByValue("username");
        }
    };

     

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
  • 07-23-2008, 4:14 PM In reply to

    • canadaka
    • Top 50 Contributor
    • Joined on 08-18-2006, 3:10 AM
    • Vancouver, Canada
    • Posts 63

    Re: Help with Output Caching and PHP

    thanks for the response. I didn't realise it used request headers.  Making a native module is above me head though, I don't really know any C++. I will try asking a friend who does if he can look at it. Unless someone here wants to tackle it and make it available to everyone. I think it could be something very useful for anyone running any kind of CMS or forums app.

  • 07-24-2008, 4:37 AM In reply to

    • canadaka
    • Top 50 Contributor
    • Joined on 08-18-2006, 3:10 AM
    • Vancouver, Canada
    • Posts 63

    Re: Help with Output Caching and PHP

    I got a friend to compile a native module with the code you psoted above, I was able to add it to IIS using the "appcmd.exe install module" command. But I don't know what to do now, as I don't really understand what the code actualy does. Do I need to change anything in the 'Output Caching' settings to work with this?

     When I added this custom module, it does make a difference. A page that was loading as a logging in user even though the request was anonymous was now loading as anonymous. But I'm not sure if the Output caching is actualy working, If i keep refreshing the page, the page counter keeps going up. When caching was working, the counter would stay static for the life of the cache (30 seconds). 

    This is the command I used to add the module, I was wondering how I can modify this to only add the module to a specific site.

    %systemroot%\system32\inetsrv\appcmd.exe install module /name:CustomCache /image:C:\inetpub\IIS7NativeModule.dll

  • 07-25-2008, 1:56 PM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 6:13 PM
    • Redmond, WA
    • Posts 1,225

    Re: Help with Output Caching and PHP

    First, did you change the "username" in my sample code with the actual username?

    Adding the module just made all your caching rules vary by logged-in user-name - you would still need to create caching rules as before to cache specific extensions etc.

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
  • 07-25-2008, 3:44 PM In reply to

    • canadaka
    • Top 50 Contributor
    • Joined on 08-18-2006, 3:10 AM
    • Vancouver, Canada
    • Posts 63

    Re: Help with Output Caching and PHP

    No i didn't change it, as I said I didn't understand what the code actually did. Thanks for letting me know, I will re-make it and try again replacing 'username' with 'anonymous'.

    Yes I added a rule with User-mode caching * query string. Is that correct, or should I be using kernal-mode.

    I did all this and it still doens't seem to be caching anything.

  • 07-25-2008, 4:12 PM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 6:13 PM
    • Redmond, WA
    • Posts 1,225

    Re: Help with Output Caching and PHP

    You do not want to replace it with another literal string but rather with the user-name for the user actually authenticated for that request.

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
  • 07-25-2008, 4:26 PM In reply to

    • canadaka
    • Top 50 Contributor
    • Joined on 08-18-2006, 3:10 AM
    • Vancouver, Canada
    • Posts 63

    Re: Help with Output Caching and PHP

    hmm i see, which is the authentication user? IUSR?

    I'm not sure what user PHP vis FastCGI authenticates with.

    Thanks for helping me with this.

  • 07-28-2008, 4:25 PM In reply to

    • anilr
    • Top 10 Contributor
    • Joined on 05-23-2006, 6:13 PM
    • Redmond, WA
    • Posts 1,225

    Re: Help with Output Caching and PHP

    It is the name of whatever user you want to vary the page by.

    Anil Ruia
    Senior Software Design Engineer
    IIS Core Server
Page 1 of 2 (16 items) 1 2 Next >
Page view counter