|
Posted by Rik Wasmus on 11/14/07 17:33
On Wed, 14 Nov 2007 16:10:53 +0100, Rob Wilkerson
<r.d.wilkerson@gmail.com> wrote:
> On Nov 14, 9:25 am, ZeldorBlat <zeldorb...@gmail.com> wrote:
>>
>> That's expected. Remember that in PHP each request is independent of
>> the next. You'll only create one instance of your class /per request/
>> but it will be available everywhere you go.
>>
>> Consider a database connection as an example. You open the connection
>> once per request, and you close it when the request is finished.
>> While the request is executing you only have/need a single connection
>> (i.e. you don't need to reconnect every time you execute a query) no
>> matter where in your code you go.
>>
>> That's how singletons work in PHP.
>
> That's what I was afraid of. Kind of makes singletons worthless (at
> least for my case), doesn't it? I could assign a new instance to a
> variable and just reference that variable through the life of the
> request. In the case of my (xml-based) config, I have to read the
> config on every single request. I was hoping to avoid that without
> using flat files or the session scope.
Not really 'normal' PHP use, normally nothing should stay in memory after
a request. You could look into the shmop_* functionality though.
http://nl2.php.net/shmop
--
Rik Wasmus
Navigation:
[Reply to this message]
|