note 109197 added to function.create-function

From: Date: Wed, 27 Jun 2012 00:17:10 +0000
Subject: note 109197 added to function.create-function
Groups: php.notes 
Request: Send a blank email to php-notes+get-188890@lists.php.net to get a copy of this message
Try this to boost performance of your scripts (increase maxCacheSize): <?php runkit_function_copy('create_function', 'create_function_native'); runkit_function_redefine('create_function', '$arg,$body', 'return __create_function($arg,$body);'); function __create_function($arg, $body) { static $cache = array(); static $maxCacheSize = 64; static $sorter; if ($sorter === NULL) { $sorter = function($a, $b) { if ($a->hits == $b->hits) { return 0; } return ($a->hits < $b->hits) ? 1 : -1; }; } $crc = crc32($arg . "\x00" . $body); if (isset($cache[$crc])) { ++$cache[$crc][1]; return $cache[$crc][0]; } if (sizeof($cache) >= $maxCacheSize) { uasort($cache, $sorter); array_pop($cache); } $cache[$crc] = array($cb = eval('return function('.$arg.'){'.$body.'};'), 0); return $cb; } ---- Server IP: 195.54.192.44 Probable Submitter: 86.62.104.98 ---- Manual Page -- http://www.php.net/manual/en/function.create-function.php Edit -- https://master.php.net/note/edit/109197 Del: integrated -- https://master.php.net/note/delete/109197/integrated Del: useless -- https://master.php.net/note/delete/109197/useless Del: bad code -- https://master.php.net/note/delete/109197/bad+code Del: spam -- https://master.php.net/note/delete/109197/spam Del: non-english -- https://master.php.net/note/delete/109197/non-english Del: in docs -- https://master.php.net/note/delete/109197/in+docs Del: other reasons-- https://master.php.net/note/delete/109197 Reject -- https://master.php.net/note/reject/109197 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#188890) next »