views:

79

answers:

1

Hi,

I'm currently developing a large site that handles user registrations. A social networking website for argument's sake. However, I've noticed a lag in page loads and deciphered that it is the creation of objects on pages that's slowing things down.

For example, I have a Member object, that when instantiated with an ID passed as a construct parameter, it queries the database for that members' row in the members database table. Not bad, but this is created each time a page is loaded; and called more than once when say, calling an array of that particular members' friends, as a new Member object is created for each friend.

So on a single page I can have upwards of seven of the same object, but containing different properties.

What I'm wanting to do is to find a way to reduce the database load, and to allow persist objects between page loads. For example, the logged in user's object to be created on login (which I can do) but then stored somewhere for retrieval so I don't have to keep re-creating the object between page loads.

What is the best solution for this? I've had a look at Memcache, but with it being a third-party module I can't have the web host install it on this occasion. What are my alternatives, and/or best practices in my case?

Thanks in advance.

+1  A: 

I believe it's generally better to cache the data received from the database, not the PHP object itself. Either way, APC, Memcache or XCache would be the way to store it.

Why not the object itself? You'd have to convert the DB array into an object again on each request, and it would still have to be serialized/unserialized anyway.
Lotus Notes
Using APC or MemCache, the object is automatically serialized when added to the cache and unserialized when fetched out
Mark Baker