Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7191507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:44:34+00:00 2026-05-28T19:44:34+00:00

So I have an object that reads a file from disk gnugpg it appears

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:44:36+00:00Added an answer on May 28, 2026 at 7:44 pm

    If it’s a small object that doesn’t take up much memory and is serializable you could just store it in 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()){
    
        switch($objectName){
    
            case('gnugpg_key_ring'):{
                $gnugpgKeyRing = getGNUPGKeyRing(); //do whatever you need to do to make the keyring.
                return serialize($countryScheme);
            }
    
            default:{
                throw new UnsupportedOperationException("Unknown object name objectName, cannot retrieve from session.");
                break;
            }
        }
    }
    
    //Call this before anything else
    function initSession(){
        session_name('projectName');
        session_start();
    }
    
    function setSessionVariable($name, $value){
        $_SESSION['projectName'][$name] = $value;
    }
    
    function getSessionVariable($name, $default = FALSE){
    
        if(isset($_SESSION['projectName'])){
            if(isset($_SESSION['projectName'][$name])){
                $value = $_SESSION['projectName'][$name];
            }
        }
        return $default;
    }
    

    and then retrieve that object by calling

    getSessionObject('gnugpg_key_ring');
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object that reads data from an Excel file using, which takes
I have a program that creates an object for each file in a directory
I have an architecture that reads packets from a packetized binary file, assigns each
I have written a program that reads in a File object (really an XML
I have an object that starts a thread, opens a file, and waits for
I have an object that can build itself from an XML string, and write
I have a program that loads a file (anywhere from 10MB to 5GB) a
I have a class, lets call it 'Words', that reads a file and creates
I have parametrized junit test that reads from several XML input files. In the
I've got a piece of an application that reads input sometimes from a file,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.