Re: Re: global variables

From: Date: Tue, 07 Dec 2004 17:55:28 +0000
Subject: Re: Re: global variables
References: 1 2 3  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-1702@lists.php.net to get a copy of this message
Wez Furlong wrote:
ZEND_MODULE_GLOBALS is intended to create per-request globals, so if you hope to maintain state between requests, this approach won't work. To maintain variables between requests, simply declare them as globals as you would normally in a C program, but note the following: - in threaded web servers you should mutex access to the globals or risk races and possible crashes - in forking web servers (eg: Apache) the globals are "local" to the current apache child. A given client is not guaranteed to hit the same process for consecutive requests, and the Apache child can be killed and recycled out from under your PHP script between requests. In other words, only per-request globals make sense under Apache. You should also be aware that PHP has the concept of isolated requests; that is, after a request is run, all state should be reset to clean, default values. There are a few special cases where this doesn't happen (persistent resource management and opcode caches being the only two things that spring to mind right now). For your particular problem, I would create the tree as a true global during MINIT (and free it in MSHUTDOWN). Provided that you don't modify the tree contents after MINIT, it should work out just fine on all SAPI. Note that loading it in MINIT will delay the initialization of PHP by however long that process takes, for each Apache/CGI child process. If it takes "too long", you might want to rethink the structure of your application. Thank you for your complete answer.
But Turck mmcache provide a function to store variable in a shared memory which is common to all process ( http://turck-mmcache.sourceforge.net/index_old.html#api ). So there must be a way to do that but I watch mmcache sources and I don't find the thing...

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