Is this possible?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Within php, is it possible to have an instance of a class that will be
the same across all executions of the script?

We are creating quite an extensive application (some of it in PHP) and
we need certain classes (for auditing etc) to only be instantiated
once (for all instances of all scripts for all users).

I did not think it was possible in php, can you confirm or deny this?


Re: Is this possible?

Quoted text here. Click to load it

Of course its possible - you just need to write it. Effectively you
are talking about an object stored in a common session - just write
your own session handler to load the universal object along with the
session. You'll need to work out how to handle the concurrency though
(typically not an issue for per-user sessions)


Re: Is this possible?

Mark Smith wrote:
Quoted text here. Click to load it

No, it's not possible in PHP.  Storing the object in a common session
won't help - when you load the object from the session, each version
will get it's own memory, and any changes to the object will not be
reflected in other objects.

You could create shared memory and have the objects reference that, but
you need to protect access with mutex semaphores.

But this makes me wonder about your design.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: Is this possible?

Jerry Stuckle wrote:

Quoted text here. Click to load it

I agree with Jerry.

But have a look at

if you're determined

Re: Is this possible?

Quoted text here. Click to load it

That sounds like a big problem with concurrency.  PHP deals with
that between pages in the same session, but not between different

Quoted text here. Click to load it

I suggest putting any data you want for the class in permanent
storage (e.g. a database).  Databases have features to deal with
concurrency, but you still have to code carefully.

Quoted text here. Click to load it

Re: Is this possible?

On Jan 6, 10:49=A0pm, (Gordon Burditt) wrote:
Quoted text here. Click to load it

I second Gordon's suggestion of using a database for the members of
your object.  However, this is a poor solution and I would recommend
trying to find any other possible solution.

It will scale badly and slow down hugely with more than a few users at
a time.  And it would require VERY careful coding to make sure you
aren't stepping on another user's toes when taking a read and then
doing a write to make sure that another user hasn't updated the field
in the time between the read and the write.

Tyler Style

Site Timeline