Re: Global variables in extensions

From: Date: Fri, 30 Mar 2001 12:20:44 +0000
Subject: Re: Global variables in extensions
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-50336@lists.php.net to get a copy of this message
Thank you very much for your answer, Zeev. It really helped me understand (to some extend) what is going on. Yes! I considered global variables to be more global than the case being :( Well I guess I should go for the shared memory approach then, but how? Reading about shmget in the man-page revealed to me, that it is necessary to store a key that is used to reference the memory segment, but how is this done! If I could store the key, then I would have no need to use shared memory. Obviously I could allocate a segment in MINIT and use this throughout, but then it wouldn't be possible for me to alter the segment size - which sounds sort of bad... Thomas Zeev Suraski wrote: > > Ah, no, it's not necessary. I thought you were talking about a dynamic > extension. > > What exactly isn't working? Is something that you're storing in a > static/global variable not retained by the time of the next request? > > A couple of things that are worth mentioning: > - You can only set the values for global/static variables during the > initial startup (minit). > - Changes you make to these values afterwards will only be retained in the > context of a single process, because the static/global variables are only > global process-wide, whereas Apache has many simultaneous processes. > > My guess is that you probably considered global variables to be more global > than they really are (i.e., across processes). In order to have variables > that are shared among all Apache processes, you're going to have to use > shared memory or some other type of persistent shared storage. > > Zeev > > At 13:16 30/3/2001, Thomas Wentzel wrote: > >Hi Zeev, > > > >My extension is compiled _into_ php which is loaded as a module in > >apache! > >I'm not using the php.ini file at the moment - is it really necessary? > > > >Thomas > > > >Zeev Suraski wrote: > > > > > > How are you loading your extension? If you're using dl(), forget about > > > retaining any type of information in between requests... You must use > > > extension= in php.ini > > > > > > Zeev > > > > > > At 11:58 30/3/2001, Thomas Wentzel wrote: > > > >Hi! > > > > > > > >I have a problem that is driving me crazy. > > > > > > > >I need to allocate some memory that will be available > > > >throughout a session. > > > > > > > >Firstly a database connection is established, but at the > > > >same time I read all relevant information about the db (records, > > > >attributes, typedeclarations and such and such). This is a rather > > > >lengthy process so I am trying to store these information in memory > > > >for later retrieval. > > > >This is the part, that doesn't work. Whenever a new page is loaded > > > >the information is lost. I have tried using static (global) > > > >variables, and I have tried the ZEND_BEGIN/END_MODULE_GLOBALS. > > > >About the ZEND_BEGIN/END... approach: the std. skeleton defines these > > > >macros: > > > >#ifdef ZTS > > > > #define RAIMAG(v) (raima_globals->v) > > > > #define RAIMALS_FETCH() php_raima_globals > > > >*raima_globals=ts_resource(raima_globals_id) > > > >#else > > > > #define RAIMAG(v) (raima_globals.v) > > > > #define RAIMALS_FETCH() > > > >#endif > > > > > > > >How do I utilize ZTS? Where is raima_globals_id defined? > > > >I do set a variable in PHP_MINIT_FUNCTION that variable is always set! > > > >But any other variables from the ZEND_BEGIN/END_MODULE_GLOBALS section > > > >(phew) > > > >that is set later do not remember their value??? Why is that? > > > > > > > >Thanks > > > > Thomas > > > > > > > >-- > > > >PHP Development Mailing List > > > ><http://www.php.net/> > > > >To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net > > > >For additional commands, e-mail: php-dev-help@lists.php.net > > > >To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > > > -- > > > Zeev Suraski <zeev@zend.com> > > > CTO & co-founder, Zend Technologies Ltd. > > > http://www.zend.com/ > > -- > Zeev Suraski <zeev@zend.com> > CTO & co-founder, Zend Technologies Ltd. > http://www.zend.com/

« previous php.dev (#50336) next »