PHP Object Caching performance

caching, object, oop, performance, php

Solution

Is there difference between caching PHP objects on disk rather than not?

As with all performance tweaking, you should measure what you're doing instead of just blindly performing some voodoo rituals that you don't fully understand. When you save an object in `$_SESSION`, PHP will capture the objects state and generate a file from it (serialization). Upon the next request, PHP will then create a new object and re-populate it with this state. This process is much more expensive than just creating the object, since PHP will have to make disk I/O and then parse the serialized data. This has to happen both on read and write.

In general, PHP is designed as a shared-nothing architecture. This has its pros and its cons, but trying to somehow sidestep it, is usually not a very good idea.

Problem

Is there difference between caching PHP objects on disk rather than not? If cached, objects would only be created once for ALL the site visitors, and if not, they will be created once for every visitor. Is there a performance difference for this or would I be wasting time doing this? Basically, when it comes down to it, the main question is: Multiple objects in memory, PER user (each user has his own set of instantiated objects) VS Single objects in cached in file for all users (all users use the same objects, for example, same error handler class, same template handler class, and same database handle class)

Original source