Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

are 'long-lived' php objects possible?

Tags:

oop

php

So, I know that the general idea in PHP is that the whole application is loaded and executed every time the page loads. But for optimization of a sizable object-oriented PHP app that needs to be portable…is it possible to load an object into memory that can be used for every request, not recreated for each one?

I've seen people using the $_SESSION variable for something like this, but that seems like it is a) ugly, b) will take up a lot of space on the server, and c) doesn't really do what I need it to as it's a session by session sort of thing.

Is there some sort of $_ALL_SESSIONS? ;)

(Or, approaching the question from a different angle, are purely static objects loaded into memory each time you load the page with a standard Apache mod-php install?)

like image 897
Aaron Yodaiken Avatar asked Feb 26 '23 12:02

Aaron Yodaiken


1 Answers

You are more or less looking for an equivalent of ASP/IIS's Application object in PHP. AFAIK there isn't one.

There is EG(persistent_list), a list of "objects" that are not (necessarily) removed after a request is served. It's used by functions like mysql_pconnect(), pg_pconnect(), ... But it is not directly accessible by script code.

memchache has already been mentioned. Can you please elaborate on "purely static objects" ?

like image 54
VolkerK Avatar answered Mar 01 '23 00:03

VolkerK