andrei Tue Aug 24 17:02:52 2004 EDT
Modified files: (Branch: PHP_5_0)
/php-src NEWS
/php-src/ext/pcre php_pcre.c
Log:
MFB
http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1760.2.53&r2=1.1760.2.54&ty=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.1760.2.53 php-src/NEWS:1.1760.2.54
--- php-src/NEWS:1.1760.2.53 Tue Aug 24 11:25:59 2004
+++ php-src/NEWS Tue Aug 24 17:02:52 2004
@@ -1,6 +1,8 @@
PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2004, PHP 5.0.2
+- Implemented periodic PCRE compiled regexp cache cleanup, to avoid memory
+ exhaustion. (Andrei)
- Added PHP_EOL constant that contains the OS way of representing newlines.
(Paul Hudson, Derick)
- Fixed bug with raw_post_data not getting set (Brian)
http://cvs.php.net/diff.php/php-src/ext/pcre/php_pcre.c?r1=1.157&r2=1.157.2.1&ty=u
Index: php-src/ext/pcre/php_pcre.c
diff -u php-src/ext/pcre/php_pcre.c:1.157 php-src/ext/pcre/php_pcre.c:1.157.2.1
--- php-src/ext/pcre/php_pcre.c:1.157 Tue Jun 22 18:21:58 2004
+++ php-src/ext/pcre/php_pcre.c Tue Aug 24 17:02:52 2004
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_pcre.c,v 1.157 2004/06/22 22:21:58 andrei Exp $ */
+/* $Id: php_pcre.c,v 1.157.2.1 2004/08/24 21:02:52 andrei Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -108,6 +108,63 @@
}
/* }}} */
+#define PCRE_CACHE_SIZE 4096
+
+/* {{{ static pcre_clean_cache */
+static void pcre_clean_cache()
+{
+ HashTable *ht = &PCRE_G(pcre_cache);
+ Bucket *p = NULL;
+ int clean_size = PCRE_CACHE_SIZE / 8;
+
+ HANDLE_BLOCK_INTERRUPTIONS();
+
+ do {
+ p = ht->pListHead;
+
+ if (ht->pDestructor) {
+ ht->pDestructor(p->pData);
+ }
+ if (!p->pDataPtr) {
+ pefree(p->pData, ht->persistent);
+ }
+
+ if (p->pLast) {
+ p->pLast->pNext = p->pNext;
+ } else {
+ uint nIndex;
+
+ nIndex = p->h & ht->nTableMask;
+ ht->arBuckets[nIndex] = p->pNext;
+ }
+ if (p->pNext) {
+ p->pNext->pLast = p->pLast;
+ } else {
+ /* Nothing to do as this list doesn't have a tail */
+ }
+
+ if (p->pListLast != NULL) {
+ p->pListLast->pListNext = p->pListNext;
+ } else {
+ /* Deleting the head of the list */
+ ht->pListHead = p->pListNext;
+ }
+ if (p->pListNext != NULL) {
+ p->pListNext->pListLast = p->pListLast;
+ } else {
+ ht->pListTail = p->pListLast;
+ }
+ if (ht->pInternalPointer == p) {
+ ht->pInternalPointer = p->pListNext;
+ }
+ pefree(p, ht->persistent);
+ ht->nNumOfElements--;
+ } while (ht->nNumOfElements > PCRE_CACHE_SIZE - clean_size);
+
+ HANDLE_UNBLOCK_INTERRUPTIONS();
+}
+/* }}} */
+
/* {{{ pcre_get_compiled_regex
*/
PHPAPI pcre* pcre_get_compiled_regex(char *regex, pcre_extra **extra, int
*preg_options TSRMLS_DC)
@@ -289,6 +346,15 @@
*compile_options = coptions;
efree(pattern);
+
+ /*
+ * If we reached cache limit, clean out the items from the head of the list;
+ * these are supposedly the oldest ones (but not necessarily the least used
+ * ones).
+ */
+ if (zend_hash_num_elements(&PCRE_G(pcre_cache)) == PCRE_CACHE_SIZE) {
+ pcre_clean_cache();
+ }
/* Store the compiled pattern and extra info in the cache. */
new_entry.re = re;
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php