Re: global variables
| From: | Justin Hannus | Date: | Mon, 06 Dec 2004 18:15:14 +0000 |
| Subject: | Re: global variables | ||
| References: | 1 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-1697@lists.php.net to get a copy of this message | ||
Please use "Reply all" so the post goes to the list.
Your code seems fine. The only thing I can think of is that maybe your
getting a segfault somewhere which causes php_first_test_init_globals() to
be called again?? Though I'm not sure that under a webserver sapi that php
module startup process would start all over again after a segfault. Try
compiling your extension with --enable-debug and watch for output, check
your webservers logs or see if you have any core dumps laying around from
it.
Maybe some-one else can comment.
-Justin
----- Original Message -----
From: "Siewn" <ml@croiset.com>
To: "Justin Hannus" <jhannus@visualconceptsinc.com>
Sent: Monday, December 06, 2004 12:45 PM
Subject: Re: [PECL-DEV] Re: global variables
> I'm sorry to disturb you with this problem, I know it's probably simple
> but I really tried many ways and I can't find the good one.
>
> I tried to do as you suggest but it doesn't work.
> Your can see ( http://ns3288.ovh.net/~dweis/test_ext.php ), if
> you refresh
> slowly the variable is well incremented but if you do it fast, it doesn't
> work any more and you can guess the variable is initialized in each apache
> process.
>
> If you can just look at my short source code, I would be really thankful.
>
> http://ns3288.ovh.net/~dweis/first_test.c.txt
> http://ns3288.ovh.net/~dweis/php_first_test.h.txt
> http://ns3288.ovh.net/~dweis/test_ext.php.txt
>
> Thanks a lot.
>
> Tristan
>
>
>>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)
>>
>>
>
>