? 610716-7_check_once.patch
Index: porterstemmer.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/porterstemmer/porterstemmer.module,v
retrieving revision 1.2.2.5
diff -u -p -r1.2.2.5 porterstemmer.module
--- porterstemmer.module	21 Oct 2009 23:47:22 -0000	1.2.2.5
+++ porterstemmer.module	22 Oct 2009 21:45:08 -0000
@@ -26,22 +26,8 @@ function porterstemmer_search_preprocess
     return $text;
   }
 
-  // See if the PECL stemming package is installed and try to load it.
-
-  $has_pecl_stem = FALSE;
-
-  if (extension_loaded( 'stem')) {
-    $has_pecl_stem = TRUE;
-  }
-  else {
-    // dynamic loading of extensions is going away in PHP 6, so leave this
-    // check here!
-    if (function_exists( 'dl' )) {
-      $has_pecl_stem = dl('stem.so');
-    }
-  }
-
-  $has_pecl_stem = $has_pecl_stem && function_exists('stem_english');
+  // Try to load stem PECL extension.
+  $has_pecl_stem = _porterstemmer_load_stem();
 
   // Process each word, skipping delimiters
   $isword = !preg_match('/' . PORTERSTEMMER_BOUNDARY . '/', $words[0] );
@@ -123,6 +109,33 @@ function porterstemmer_sbp_excerpt_match
 }
 
 /**
+ * Helper function for loading PECL stem extension.
+ *
+ * @return
+ *   Returns TRUE if extension could be loaded and stem_english() is available.
+ *   FALSE otherwise.
+ */
+function _porterstemmer_load_stem() {
+  static $has_pecl_stem = NULL;
+
+  if ($has_pecl_stem === NULL) {
+    if (extension_loaded( 'stem')) {
+      $has_pecl_stem = TRUE;
+    }
+    else {
+      // dynamic loading of extensions is going away in PHP 6, so leave this
+      // check here!
+      if (function_exists( 'dl' )) {
+        $has_pecl_stem = @dl('stem.so');
+      }
+    }
+    $has_pecl_stem = $has_pecl_stem && function_exists('stem_english');
+  }
+
+  return $has_pecl_stem;
+}
+
+/**
  * Regular expression defining a vowel for Porter Stemmer purposes.
  */
 define('PORTERSTEMMER_VOWEL', '[aeiouy]');
