apache - Is there a way to keep a php object in memory to avoid disk reads and wirtes? -



apache - Is there a way to keep a php object in memory to avoid disk reads and wirtes? -

so have object reads file disk gnugpg appears create gnugpg key ring in home directory.

i want avoid having load object every time php script called apache.

is there away have php object remain in memory?

if it's little object doesn't take much memory , serializable store in session:

function getsessionobject($objectname, $params){ $sessionobjectserialized = getsessionvariable($objectname, false); if($sessionobjectserialized == false){ $sessionobjectserialized = constructsessionobject($objectname, $params); setsessionvariable($objectname, $sessionobjectserialized); } $sessionobject = unserialize($sessionobjectserialized); homecoming $sessionobject; } function constructsessionobject($objectname, $params = array()){ switch($objectname){ case('gnugpg_key_ring'):{ $gnugpgkeyring = getgnupgkeyring(); //do whatever need create keyring. homecoming serialize($countryscheme); } default:{ throw new unsupportedoperationexception("unknown object name objectname, cannot retrieve session."); break; } } } //call before 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]; } } homecoming $default; }

and retrieve object calling

getsessionobject('gnugpg_key_ring');

however not objects serializable e.g. if object holds file handle open file, need have code close file when object serialized , re-open file when object unserialized.

if object large, improve off using proper caching tool memcached store serialized object, rather session.

php apache file-io gnupg

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -