How to store included/required files in persistent memory?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mecha_godzilla
Forum Contributor
Posts: 375
Joined: Wed Apr 14, 2010 4:45 pm
Location: UK

How to store included/required files in persistent memory?

Post 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
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

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

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

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

Post 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
User avatar
mecha_godzilla
Forum Contributor
Posts: 375
Joined: Wed Apr 14, 2010 4:45 pm
Location: UK

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

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

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

Post 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.
User avatar
mecha_godzilla
Forum Contributor
Posts: 375
Joined: Wed Apr 14, 2010 4:45 pm
Location: UK

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

Post 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
Post Reply