Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
Thread: Single instance across requests
05-16-2009, 10:07 AM #1
Single instance across requests
I'm not much of a server-side person, but my limited experience with PHP and its ilk seem to suggest that variables and functions exist on a per-request basis. E.g. I hit page.php and every variable and function is redeclared and re-executed, which is fine if my data is in a database and I'm just pulling from a database every time.
However, I have a collection of data that is best represented by an abstract data-type that is very distinctively not a database. (Both query-wise and storage-wise, a database is simply the wrong way to deal with it -- my own representation has orders of magnitude improvements in both aspects.)
So my question is (and I'm open to language suggestions), how do I maintain a single object instance across requests? Could I use a Java servlet and declare it to be a static class variable? Is there some feature of PHP that I missed by living under a rock? (Wasn't the whole point of moving away from CGI so that we could run a single interpreter for every request, rather than spawning a new process every time? If that's the case, shouldn't there be a nice way to maintain an object at the interpreter level?)
I don't think concurrency will be an issue, since I am hoping to send static dumps of pre-calculated portions of the structure to the client in the form of JS (so clients never actually modify the structure directly or talk to it dynamically; rather, they just query from what they are sent, which is a flat-file representation). Although, having the ability to talk directly to the abstract data type on every request might be required in the future -- perhaps a job for Erlang or something?
I'm sorry for my ignorance on the matter, so be patient with me.