Re: global variables

From: Date: Mon, 06 Dec 2004 14:08:17 +0000
Subject: Re: global variables
References: 1  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-1696@lists.php.net to get a copy of this message
You can do this with a combo of your extension globals struct, which you should have defined in your php_ext.h file generated by PECL_Gen or ext_skel, and your PHP_MINIT_FUNCTION which is called at module startup. Its counterpart is the PHP_MSHUTDOWN_FUNCTION. On module startup you can build your tree in the PHP_MINIT_FUNCTION and store it in your extension globals struct, which can be accessed by other functions in your extension. Just remember to free any memory that you emalloc in your PHP_MINIT_FUNCTION with your PHP_MSHUTDOWN_FUNCTION. You can find examples in just about all extension source code. -Justin "Siewn" <ml@croiset.com> wrote in message news:41B233D6.9000401@croiset.com... > Hi, > > I writing an extension for text search tools and I have a little problem > with global variables. > In each search, I use a binary tree which is always the same. So it's a > waste of time to build this tree every time I call my search function. > Then I would prefer create this tree just one time, when the extension is > loaded (when apache & php start) and always access to this same data. > But I can't find how to do this. I try to create a variable just under /* > True global resources - no need for thread safety here */ but I assume > it's not good because this variable seems to be dependant on each apache > process... > I'm sure there's a solution because turckmmcache store data in such global > variable but I can't really understand how it did it. > > Thanks a lot > > -- > tristan (who must improve his english)

« previous php.pecl.dev (#1696) next »