Text Statistics is a PEAR package to calculate statistics for documents including readability scores. One of its more intensive operations is calculating the number of syllables in a word, which is calculated through a number of regexps. We can improve its performance on moderate-large documents by caching word objects.

<?php
require_once "Text/Word.inc";

class WordFactory {
  static $objects;
  function Word($name) {
    $nobject = &self::$objects['Word'][$name];
    
    if (!$nobject) {
      $nobject = new Word($name);
    }

    return $nobject;
  }
}
?>