And So I come with an object that reads personal files from disk gnugpg it seems to continually produce a gnugpg key ring in the home directory.

I wish to avoid needing to load this object whenever a php script is known as from apache.

can there be away to possess a php object remain in memory?

Whether it's a little object that does not occupy much memory and it is serializable you can just store it within the session:

function    getSessionObject($objectName, $params){

    $sessionObjectSerialized = getSessionVariable($objectName, FALSE);

    if($sessionObjectSerialized == FALSE){
        $sessionObjectSerialized = constructSessionObject($objectName, $params);
        setSessionVariable($objectName, $sessionObjectSerialized);

    $sessionObject = unserialize($sessionObjectSerialized);

    return $sessionObject;

function    constructSessionObject($objectName, $params = array()){


            $gnugpgKeyRing = getGNUPGKeyRing(); //do whatever you need to do to make the keyring.
            return serialize($countryScheme);

            throw new UnsupportedOperationException("Unknown object name objectName, cannot retrieve from session.");

//Call this before anything else
function initSession(){

function setSessionVariable($name, $value){
    $_SESSION['projectName'][$name] = $value;

function getSessionVariable($name, $default = FALSE){

            $value = $_SESSION['projectName'][$name];
    return $default;

after which retrieve that object by calling


However not every objects will always be serializable e.g. when the object holds personal files handle for an open file, that will have to possess some extra code to shut the file once the object is serialized after which re-open the file once the object was unserialized.

When the object is big, you would then be best utilizing a proper caching tool like memcached to keep the serialized object, as opposed to the session.