Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:6123 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86119 invoked by uid 1010); 3 Dec 2003 17:15:09 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 86022 invoked from network); 3 Dec 2003 17:15:08 -0000 Received: from unknown (HELO mx.thebrainroom.net) (65.200.24.98) by pb1.pair.com with SMTP; 3 Dec 2003 17:15:08 -0000 Received: by mx.thebrainroom.net (Postfix, from userid 517) id 4DF501488089; Wed, 3 Dec 2003 09:14:15 -0800 (PST) Received: from obsidian (zaneeb.thebrainroom.net [82.133.1.138]) by mx.thebrainroom.net (Postfix) with ESMTP id 39F7C1488087; Wed, 3 Dec 2003 09:13:40 -0800 (PST) Message-ID: <0b9d01c3b9c0$c0846f70$8802a8c0@obsidian> To: , , "Uwe Schindler" References: <6.0.1.1.0.20031203175354.039cac08@127.0.0.1> Date: Wed, 3 Dec 2003 17:13:19 -0000 Organization: The Brain Room Ltd. MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Spam-Status: No, hits=-0.9 required=5.0 tests=AWL,BAYES_30,QUOTED_EMAIL_TEXT,REFERENCES version=2.55 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp) X-TBR-Filter: Virus scanned and defanged Subject: Re: [PHP-DEV] browscap and nesting level too deep (bug #25916) From: wez@thebrainroom.com ("Wez Furlong") We have thread-safe hashes in php5; browscap should probably use one of those there. If you want to roll your own protection, take a look at tsrm_mutex_lock() and tsrm_mutex_unlock() and how they are used in ext/yaz. --Wez. ----- Original Message ----- From: "Uwe Schindler" To: ; Sent: Wednesday, December 03, 2003 5:06 PM Subject: [PHP-DEV] browscap and nesting level too deep (bug #25916) > Today I got the error from bug #25916 several times on our webserver. > Looking through the code I found out the following: > * It depends NOT on the fact if there is a parameter to get_browser() or not > * It happens sometimes when server is very heavy loaded, the homepage of > the domain uses the get_browser() function and is the most visited page. > > So it must be a multithreading issue (NSAPI is a multithreading webserver). > And I have an idea: > Line 257 uses: > zend_hash_apply_with_arguments(&browser_hash, (apply_func_args_t) > browser_reg_compare, 2, lookup_browser_name, &found_browser_entry); > > This is the only function in this context in zend_hash.c which uses the > Recursion protection with > #define > HASH_PROTECT_RECURSION(ht) > \ > if ((ht)->bApplyProtection) > { > \ > if ((ht)->nApplyCount++ >= 3) > { > \ > zend_error(E_ERROR, "Nesting level too deep - > recursive dependency?"); \ > } > \ > } > > The browser hashtable is a global variable in browscap.c and can be used by > more than one call to get_browser() even at the same time. So if one > zend_hash_apply_with_arguments() locks the hashtable and a second and third > thread tries to do that you will get the error, because (ht)->nApplyCount++ > raises and raises... > > This evening I will try to put a mutex at the beginning of get_browser to > prevent more threads running at the same time there. But as I see this, > this zend_hash_apply function is used very often could there be other > effects if a global variable is a hashtable? > > Only one question: Is there a special PHP way to use mutexes? I am not > familar in Zend programming (I do only SAPI...)