Hello,
I'm working on a PHP extension that maintains a [int -> SVG XML DOM
Structure] map that should be persistent through user requests to the
server.
I initialize and allocate my one and only global variable in
PHP_MINIT_FUNCTION through the ZEND_INIT_MODULES macro with the
function php_myext_init_globals (see below).

All works fine except the data in this object between requests is
inconsistent. I suppose that is because I have Apache compiled with
mpm-prefork which upon incoming request copies the parent process and
then modifies the __copy__ of my global object, not particular object
itself.

One solution, I suppose, would be recompiling Apache with mpm-worker
option though I'm afraid that won't be really a solution because it is
a "hybrid multi-threaded  multi-__process__" which again does not
guarantee that any process copies won't be made. Please, correct me if
I'm wrong here.

The other option that comes in my mind is maintaining this global
object in a shared memory space and request that memory from every
process created. That is an option quite hard to implement though.

Actually, I don't think these things should be so complicated here to
achieve my goal. That is the reason I'm writing this. So the question
is:

Is it possible to maintain a global persistent object in Apache
mpm-prefork? If it is not, can this problem be solved with Apache
mpm-worker?

Thanks,
Martin


P.S. I use bunch of other libraries like libxml and glib for extension
internal workings though I suppose this fact is irrelevant to the
problem described.

static void php_myext_init_globals(zend_myext_globals *myext_globals TSRMLS_DC)
{       
        g_type_init();
        myext_globals->myext_container = pemalloc(sizeof(php_myext_container), 
1);
        myext_globals->myext_container->my_hashtable =
g_hash_table_new(g_int_hash, g_int_equal);
}

where structure php_myext_container is defined as follows:

ZEND_BEGIN_MODULE_GLOBALS(myext)
        php_myext_container* myext_container;
ZEND_END_MODULE_GLOBALS(myext)

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to