2

I am trying to figure out how to cache 'chat' for a site that uses php, and the variables passed need to have unique versions per variable. ie: the chat cache for id 1 shouldnt be the same as id2, since id1 doesnt need to see id2s private messages.

In C#, you can use something akin to:

<%@ OutputCache Duration="4" VaryByParam="param1;param3" %>

This caches the page for 4 seconds, and will cache unique copies if the param1 and param3 are different between the cached pages.

Is there such a thing in php?

3
  • I would love to help if I would only understand what you are trying to achieve with this chat and cache thingy. Somehow this looks like you are dealing with sessions here. Commented Jul 8, 2011 at 19:26
  • I want to cache a page every 4 seconds, but allow that cache to be unique to each variable needed. The type of variable shouldn't have an affect on the outcome. Commented Jul 8, 2011 at 19:59
  • Somehow I understand that but this sounds to me like you want your PHP script to run non-stop? A C# application is loaded into memory and runs independently, non stop or until terminated otherwise. A PHP is a script running inside a scripting host. You can loop infinitely and sleep in between but that would not work inside a web server. The web server calls the scripting host expects a response (a HTML page) at some point or responses with 500 error. Commented Jul 8, 2011 at 22:02

1 Answer 1

1

PHP doesn't have anything like output caching built in; you'll have to either write your own implementation (which isn't too difficult for something like what you're talking about) or use an existing implementation. I believe that the Smarty templating engine has something similar built in, but it may be too late for you to implement something like that without a lot of trouble.

If you're up to writing your own implementation, I'd look into memcached to cache your data; then you could just create keys like this for your cached HTML:

$cachekey = "chat_param1:" . $param1 . '-param3:' . $param3);

That way you have a unique key for each possible value of param1 and param3.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.