So I have an object that reads a file from disk gnugpg it appears to always create a gnugpg key ring in a home directory.
I want to avoid having to load this object every time a php script is called from apache.
is there away to have a php object stay in memory?
If it’s a small object that doesn’t take up much memory and is serializable you could just store it in the session:
and then retrieve that object by calling
However not all objects are always serializable e.g. if the object holds a file handle to an open file, that would need to have some extra code to close the file when the object is serialized and then re-open the file when the object was unserialized.
If the object is large, then you would be better off using a proper caching tool like memcached to store the serialized object, rather than the session.