Page 1 of 1

Application data persistence in PHP

Posted: Mon Mar 24, 2003 12:24 pm
by sausheong
Hi,

Hope this question doesn't sound too dumb -- I'm a JSP programmer who's really new in PHP and I'm looking to do something that I'm able to do in JSP/Servlets but can't seem to find the equivalent in PHP. I want to be able to load up data into memory and persist it throughout the lifecycle of the PHP application. I want to do this so in order to keep certain data in memory that I usually will load only once and will change very infrequently.

I've been looking into global variables but that doesn't look too promising. Am I missing something important here? I'm really new in PHP.

Thanks.

Posted: Mon Mar 24, 2003 12:33 pm
by McGruff
serialize() might be what you're looking for - see manual

Posted: Mon Mar 24, 2003 12:44 pm
by sausheong
Actually what I wanted to do is to read some XML up into memory and access it whenever I need it. In Java I would use a Singleton and retrieve the instance that is stored in memory everytime I need it. I don't want to read the same XML file for every user that logs in because file access is rather expensive. How can I do the same in PHP?

Thanks for your help!

Posted: Mon Mar 24, 2003 1:56 pm
by hedge
never used it, but here's a link to the shared memory section of the php site http://www.php.net/manual/en/ref.shmop.php

Posted: Mon Mar 24, 2003 6:28 pm
by volka
implementing a GoF Singleton pattern in php might be difficult since to my knowledge there is not much kept in memory between two requests; the lifecycle of php is different from jsp's.