3
You can speed it up by caching the token for a period of time with the following routine it uses the
XoopsCache object to store the token, between one minute and one hour..
le="color: #000000"><?php /** * Function: makeRandomSeeded() - Seeds the Selection Process of Random Sorting & Selection (Using XoopCache to speed up) * * @param $filename string - Source of Seeding XML * @return integer - the seed used */ function makeRandomSeeded($filename = 'http://seed.feeds.labs.coop/') { error_reporting(E_ERROR); include_once $GLOBALS['xoops']->path('/class/cache/xoopscache.php'); if (!$seeds = XoopsCache::read('randomisation_seeds_tokens')) { // Loads XML by forcing loadXML with DOM $xml = file_get_contents($filename); $doc = new DOMDocument(); $doc->loadXML($xml); // Parses Description Tag and Remove help and File Descriptor $skip = array('This feed can', 'Current mode is'); $elements = $doc->getElementsByTagName('description'); foreach($elements as $element) { $seed = $element->nodeValue; $found = false; foreach($skip as $find) { if (substr($seed, 0, strlen($find))==$find) { $found = true; } } if ($found==false) $seeds[] = $seed; } XoopsCache::write('randomisation_seeds_tokens', $seeds, mt_rand(60, 3600)); } // Selects Seed from $seeds shuffle($seeds); $seed = $seeds[mt_rand(0, count($seeds)-1)]; unset($seeds); // Makes a Double Precision Number or Floating Point $parts = explode(' ', $seed); foreach($parts as $key => $value) if (!is_numeric($value) && is_string($value)) unset($parts[$key]); shuffle($parts); $keys = array_keys($parts); switch((string)mt_rand(0,11)) { default: $float = ($parts[$keys[mt_rand(0, count($keys)-1)]] * sqrt(microtime(true))); break; case "1": $float = ($parts[$keys[mt_rand(0, count($keys)-1)]] / sqrt(microtime(true))); break; case "2": $float = ($parts[$keys[mt_rand(0, count($keys)-1)]] - sqrt(microtime(true))); break; case "3": $float = ($parts[$keys[mt_rand(0, count($keys)-1)]] + sqrt(microtime(true))); break; case "4": $float = (sqrt($parts[$keys[mt_rand(0, count($keys)-1)]]) * microtime(true)); break; case "5": $float = (sqrt($parts[$keys[mt_rand(0, count($keys)-1)]]) / microtime(true)); break; case "6": $float = (sqrt($parts[$keys[mt_rand(0, count($keys)-1)]]) - microtime(true)); break; case "7": $float = (sqrt($parts[$keys[mt_rand(0, count($keys)-1)]]) + microtime(true)); break; case "8": $float = (sqrt($parts[$keys[mt_rand(0, count($keys)-1)]]) * sqrt(microtime(true))); break; case "9": $float = (sqrt($parts[$keys[mt_rand(0, count($keys)-1)]]) / sqrt(microtime(true))); break; case "10": $float = (sqrt($parts[$keys[mt_rand(0, count($keys)-1)]]) - sqrt(microtime(true))); break; case "11": $float = (sqrt($parts[$keys[mt_rand(0, count($keys)-1)]]) + sqrt(microtime(true))); break; } unset($keys); unset($parts); // Constructs Integer from Floating Point/Double $parts = explode(".", $float); if (count($parts)==2) { switch((string)mt_rand(0,7)) { default: $int = (integer)$float; break; case "1": $int = $parts[0] * $parts[1]; break; case "2": $int = $parts[0] . $parts[1]; break; case "3": $int = $parts[1] . $parts[0]; break; case "4": $int = (integer)($parts[1] / $parts[0]); break; case "5": $int = (integer)($parts[0] / $parts[1]); break; case "6": $int = (integer)($parts[1] * $parts[0]); break; case "7": $int = (integer)($parts[0] * $parts[1]); break; } } else { $int = (integer)$float; } // Randomise the Seeding with Integer if (!headers_sent()) header('Context-seed: ' . sha1($int)); return $int; } // Call Routine to Randomise Seed mt_srand(makeRandomSeeded()); srand(makeRandomSeeded());