Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:42087 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87667 invoked from network); 2 Dec 2008 09:45:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Dec 2008 09:45:31 -0000 Authentication-Results: pb1.pair.com smtp.mail=martins.barinskis@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=martins.barinskis@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.11 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: martins.barinskis@gmail.com X-Host-Fingerprint: 209.85.217.11 mail-gx0-f11.google.com Received: from [209.85.217.11] ([209.85.217.11:59084] helo=mail-gx0-f11.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C9/0D-16980-AB305394 for ; Tue, 02 Dec 2008 04:45:31 -0500 Received: by gxk4 with SMTP id 4so394664gxk.23 for ; Tue, 02 Dec 2008 01:45:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:mime-version:content-type:content-transfer-encoding :content-disposition; bh=ZOOJzCXex/gWJ+7h3RkdojQl5YKYWv84ONHmL1f4jEo=; b=UetHOYdlWnjePaeaEqmJ7LwUSNSt5iZ9E13DNjuiYrZS1CJf+dXAKfAkJcoDF7UFGU bNF51xtpqDIki7rthAWYt1rQuU9CS8KUj2q6jb89wQIpPq4EgR132GRnaUdTOJ71s2Yb /ikHXxMdf2aBJFTmkZxrmtBVEwQt/9/y7H3Es= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type :content-transfer-encoding:content-disposition; b=pSblt6yQtB35hasIM9GEb2U8/Hh0PqX4BTiilGpxWAK9dlBGwHTmVgwuKwOui59clo 3erSONEW5Eq0NQ7Qz1sQp6eT9OAZ5i+5PHmbErICgMDXP2J7Ib6P4+TmodkhE+npOIhq ruyEfuD0hVOmyM0Tfa3O5rdzpRUNfxpx5WloM= Received: by 10.150.149.19 with SMTP id w19mr23617844ybd.114.1228211127991; Tue, 02 Dec 2008 01:45:27 -0800 (PST) Received: by 10.151.73.13 with HTTP; Tue, 2 Dec 2008 01:45:27 -0800 (PST) Message-ID: Date: Tue, 2 Dec 2008 11:45:27 +0200 To: internals@lists.php.net MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Subject: Managing a persistent object in a PHP extension From: martins.barinskis@gmail.com ("=?ISO-8859-13?Q?M=E2rti=F2=F0_Barinskis?=") 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)