Page 1 of 1

How to store included/required files in persistent memory?

Posted: Thu Mar 31, 2011 3:36 pm
by mecha_godzilla
Hi,

Does anyone know if it's possible to load an included file into memory that will persistent between sessions, or for the duration of the server being up?

I have a number of files that get included in every script I use and it seems suboptimal for the server to keep reading-in the same files constantly, assuming that this is what it's actually doing. I'm not using Zend frameworks or anything like that and my version of PHP is 5.1.6.

Thanks,

Mecha Godzilla

Re: How to store included/required files in persistent memor

Posted: Thu Mar 31, 2011 9:37 pm
by McInfo
PHP's build-up-tear-down approach is mostly due to the statelessness of the hypertext transfer protocol (HTTP). There is no way to know when or if a client will send another request. Rather than keep a process open for a user who may not return, PHP makes room for other users.

I'm sure it is possible to write a heavyweight, persistent program controlled by a lightweight Web interface, but I'm not sure how much of a performance improvement, if any, it would have over a conventional Web application.

One thing that may boost performance is a caching strategy to limit repeated processing.

It might be helpful to use a profiler to see where most of the processing time is spent in your application.

Re: How to store included/required files in persistent memor

Posted: Fri Apr 01, 2011 3:24 am
by Weirdan
mecha_godzilla wrote:Does anyone know if it's possible to load an included file into memory that will persistent [...] for the duration of the server being up?
http://us2.php.net/apc

Re: How to store included/required files in persistent memor

Posted: Fri Apr 01, 2011 3:39 pm
by mecha_godzilla
Thanks for that - I wasn't aware that something like the ACP extension existed.

McInfo - the issue for me wasn't as such that I needed the server to maintain state with the client; what I wanted was a way to load files into shared memory so that they'd be immediately available to my scripts. The application I'm working on includes 5 or 6 separate files each time any of the scripts are called and these files are a combination of language profiles, code libraries and custom session handlers. I didn't want to put everything in one big file because I wanted the flexibility to (say) load in the German language profile and the file-based session handler as opposed to the French language profile and database-based session handler.

Without wishing to demand any more help from anyone, is PECL normally installed by default with PHP or do I need to add it? How can I find out if I have it installed?

Thanks again - have a good weekend,

M_G

Re: How to store included/required files in persistent memor

Posted: Fri Apr 01, 2011 5:17 pm
by Weirdan
Without wishing to demand any more help from anyone, is PECL normally installed by default with PHP or do I need to add it?
It depends. For hosting providers - you need to ask yours (if they have | to install) extensions you need. For a local development server - normally yes, provided that you use a flavour of Unix. For windows you would need to find a precompiled dll for the extension you need, pecl pretty much doesn't work there.
How can I find out if I have it installed?
by running 'pecl' in the command line.

Re: How to store included/required files in persistent memor

Posted: Fri Apr 01, 2011 6:42 pm
by mecha_godzilla
Thanks - I'll try the 'pecl' command in a moment. The server is a CentOS managed solution which - according to the company in question - probably means "we managed to turn the server on for you, don't expect any other help", so I'll have to install it myself if it isn't there :)

EDIT: Just checked the server and PECL is in there (no modules loaded as yet though) so I can start taking a look at APC now.

M_G