public function _initCache() { //$servers = array(); $cacheCfg = $this->_config->memcached->config; $servers = $cacheCfg->toArray(); if (!empty($servers)) { phpFastCache::$storage = "auto"; $cache = __c($cacheCfg->type); $server = array(array($cacheCfg->host, $cacheCfg->port, $cacheCfg->timeout)); $cache->option("server", $server); Registry::set("cache", $cache); } }
public function testAction() { phpFastCache::$storage = "auto"; $cache = __c("memcache"); $server = array(array("192.168.10.122", 11211, 100)); $cache->option("server", $server); $cache->keyword = array("something here++++++++++++++++_________", 600); // var_dump($cache->get("31lh9kj9cs3627fauu90njuj26")); var_dump($cache->keyword); $excel = new CreateExcel(); // $excel->setHeader('高子航' . date('Y年m月d日 H:i:s', time())); // $excel->setTitle(array( '高子航')); // $excel->setData(array()); // $excel->echoExcel('show_' . date('Y_m_d_H_i_s', time())); die; }
function __construct($storage = "", $option = array()) { if (isset(self::$config['fallback'][$storage])) { $storage = self::$config['fallback'][$storage]; } if ($storage == "") { $storage = self::$storage; self::option("storage", $storage); } else { self::$storage = $storage; } $this->tmp['storage'] = $storage; $this->option = array_merge($this->option, self::$config, $option); if ($storage != "auto" && $storage != "" && $this->isExistingDriver($storage)) { $driver = "phpfastcache_" . $storage; } else { $storage = $this->autoDriver(); self::$storage = $storage; $driver = "phpfastcache_" . $storage; } require_once dirname(__FILE__) . "/drivers/" . $storage . ".php"; $this->option("storage", $storage); if ($this->option['securityKey'] == "auto" || $this->option['securityKey'] == "") { $suffix = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : get_current_user(); $this->option['securityKey'] = "cache.storage." . $suffix; } $this->driver = new $driver($this->option); $this->driver->is_driver = true; }
<?php // phpFastCache Library require_once dirname(__FILE__) . "/phpfastcache/2.4.2/base.php"; // OK, setup your cache phpFastCache::$storage = "files"; //memcache phpFastCache::$config = array("storage" => phpFastCache::$storage, "fallback" => "files", "securityKey" => "auto", "htaccess" => true, "path" => "", "memcached" => array(array("127.0.0.1", 11211, 1)), "memcache" => array(array("127.0.0.1", 11211, 1)), "server" => array(array("127.0.0.1", 11211, 1)), "redis" => array("host" => "127.0.0.1", "port" => "", "password" => "", "database" => "", "timeout" => ""), "extensions" => array()); phpFastCache::setup(phpFastCache::$config); // temporary disabled phpFastCache phpFastCache::$disabled = false; // default chmod | only change if you know what you are doing phpFastCache::$default_chmod = ""; // keep it blank, it will use 666 for module and 644 for cgi
function __construct($storage = "", $option = array()) { if ($storage == "") { $storage = self::$storage; self::option("storage", $storage); } else { self::$storage = $storage; } $this->tmp['storage'] = $storage; $this->option = array_merge($this->option, self::$config, $option); if ($storage != "auto" && $storage != "" && $this->isExistingDriver($storage)) { $driver = "phpfastcache_" . $storage; } else { $storage = $this->autoDriver(); self::$storage = $storage; $driver = "phpfastcache_" . $storage; } require_once dirname(__FILE__) . "/drivers/" . $storage . ".php"; $this->option("storage", $storage); if ($this->option['securityKey'] == "auto" || $this->option['securityKey'] == "") { $suffix = isset($_SERVER['HTTP_HOST']) ? str_replace("www.", "", strtolower($_SERVER['HTTP_HOST'])) : get_current_user(); $this->option['securityKey'] = "cache.storage." . $suffix; } $this->driver = new $driver($this->option); $this->fallback = !$this->driver->checkdriver(); // do fallback if (method_exists($this->driver, "connectServer")) { $this->driver->connectServer(); } if ($this->driver->fallback === true) { // echo 'Fall Back'; require_once dirname(__FILE__) . "/drivers/" . $this->option['fallback'] . ".php"; $driver = "phpfastcache_" . $this->option['fallback']; $this->option("storage", $this->option['fallback']); $this->driver = new $driver($this->option); $this->driver->is_driver = true; $this->fallback = true; } else { $this->driver->is_driver = true; $this->fallback = false; } }
function __construct($storage = "", $option = array()) { if (isset(self::$config['fallback'][$storage])) { $storage = self::$config['fallback'][$storage]; } if ($storage == "") { $storage = self::$storage; self::option("storage", $storage); } else { self::$storage = $storage; } $this->tmp['storage'] = $storage; $this->option = array_merge($this->option, self::$config, $option); if ($storage != "auto" && $storage != "" && $this->isExistingDriver($storage)) { $driver = "phpfastcache_" . $storage; } else { $storage = $this->autoDriver(); self::$storage = $storage; $driver = "phpfastcache_" . $storage; } $this->option("storage", $storage); if ($this->option['securityKey'] == "auto" || $this->option['securityKey'] == "") { $this->option['securityKey'] = "cache.storage." . $_SERVER['HTTP_HOST']; } $this->driver = new $driver($this->option); $this->driver->is_driver = true; }
public static function setup($name, $value = "") { if (!is_array($name)) { if ($name == "storage") { self::$storage = $value; } self::$config[$name] = $value; } else { foreach ($name as $n => $value) { self::setup($n, $value); } } }
<?php include "php_fast_cache.php"; phpFastCache::$storage = "auto"; // ready ? // check in case first $content = phpFastCache::get("keyword1"); if ($content == null) { // for testing echo "This is not caching, page is render with lot queires and slow speed <br>"; // do what you want, like get content from cURL | API | mySQL Query and return result to $content $content = file_get_contents("http://www.phpfastcache.com/testing.php"); // rewrite cache for other request in 5 seconds phpFastCache::set("keyword1", $content, 5); } else { // use cache // node echo "THIS TIME USE CACHE, FAST! <br>"; } echo "TRY F5 to refesh the page to see new SPEED with Cache!<br>"; echo $content;
$caching = array("auto", "files", "pdo", "mpdo", "xcache", "apc", "memcache", "memcached", "wincache"); $tmp = new phpFastCache(); // data use for caching ^ testing $data = array(1, "abc hello world", "", null, 0, array(1, 2, 3, 4, "string", null, "", "GOT IT", "KEY" => "VALUE", "N" => null, "E" => "", "X" => -1)); // $data = array(null,null,"",null); echo "Try get Server information ... Take 10 - 15 seconds to detect ...<br>"; phpFastCache::debug(phpFastCache::systemInfo()); echo "<b>Data will be testing - Included NULL and Emptry String</b>"; phpFastCache::debug($data); $c = array("red", "blue", "green", "orange", "black", "red", "blue", "green", "orange", "black"); $xx = 0; foreach ($caching as $st) { $dem = 0; $color = $c[$xx]; $xx++; phpFastCache::$storage = $st; echo "<font color={$color} >\n ------------------------------------------------- <br>\n Caching = {$st} <br>"; if (isset(phpFastCache::$sys['drivers'][$st]) && phpFastCache::$sys['drivers'][$st] == true || $st == "auto") { foreach ($data as $string) { $dem++; echo "SET {$dem} --> "; phpFastCache::set("A" . $dem, $string); echo "GET {$dem} = "; $x = phpFastCache::get("A" . $dem); if (is_array($x)) { print_r($x); } else { echo $x; if (is_numeric($x)) { phpFastCache::increment("A" . $dem); phpFastCache::increment("A" . $dem);
public static function autoconfig($name = "") { // self::startDebug($name,"Check Name",__LINE__,__FUNCTION__); $cache = self::cacheMethod($name); if ($cache != "" && $cache != self::$storage && $cache != "auto") { return $cache; } // self::startDebug($cache,"Check Cache",__LINE__,__FUNCTION__); $os = self::getOS(); // self::startDebug(self::$storage,"User Set",__LINE__,__FUNCTION__); if (self::$storage == "" || self::$storage == "auto") { // self::startDebug(self::$storage,"User Set Auto",__LINE__,__FUNCTION__); if (extension_loaded('apc') && ini_get('apc.enabled') && strpos(PHP_SAPI, "CGI") === false) { self::$sys['drivers']['apc'] = true; self::$sys['storage'] = "memory"; self::$sys['method'] = "apc"; // self::startDebug(self::$sys,"GOT APC",__LINE__,__FUNCTION__); } elseif (extension_loaded('xcache')) { self::$sys['drivers']['xcache'] = true; self::$sys['storage'] = "memory"; self::$sys['method'] = "xcache"; // self::startDebug(self::$sys,"GOT XCACHE",__LINE__,__FUNCTION__); } else { // fix PATH for existing $reconfig = false; // self::startDebug(self::getPath()."/config.".$os['unique'].".cache.ini","CHECK CONFIG FILE",__LINE__,__FUNCTION__); if (file_exists(self::getPath() . "/config." . $os['unique'] . ".cache.ini")) { $info = self::decode(file_get_contents(self::getPath() . "/config." . $os['unique'] . ".cache.ini")); // self::startDebug($info,"CHECK INFO",__LINE__,__FUNCTION__); if (!isset($info['value'])) { $reconfig = true; } else { $info = $info['value']; self::$sys = $info; } } else { $info = self::systemInfo(); // self::startDebug($info,"CHECK INFO BY SYSTEM INFO",__LINE__,__FUNCTION__); } if (isset($info['os']['unique'])) { if ($info['os']['unique'] != $os['unique']) { $reconfig = true; } } else { $reconfig = true; } if (!file_exists(self::getPath() . "/config." . $os['unique'] . ".cache.ini") || $reconfig == true) { $info = self::systemInfo(); self::$sys = $info; // self::startDebug($info,"Check Info",__LINE__,__FUNCTION__); try { $f = fopen(self::getPath() . "/config." . $os['unique'] . ".cache.ini", "w+"); fwrite($f, self::encode($info)); fclose($f); } catch (Exception $e) { die("Please chmod 0777 " . self::getPath() . "/config." . $os['unique'] . ".cache.ini"); } } else { } } self::$storage = self::$sys['method']; } else { if (in_array(self::$storage, array("files", "pdo", "mpdo"))) { self::$sys['storage'] = "disk"; } elseif (in_array(self::$storage, array("apc", "memcache", "memcached", "wincache", "xcache"))) { self::$sys['storage'] = "memory"; } else { self::$sys['storage'] = ""; } if (self::$sys['storage'] == "" || !in_array(self::$storage, self::$supported_api)) { die("Don't have this Cache " . self::$storage . " In your System! Please double check!"); } self::$sys['method'] = strtolower(self::$storage); } if (self::$sys['method'] == "files") { $last_cleanup = self::files_get("last_cleanup_cache"); if ($last_cleanup == null) { self::files_cleanup(); self::files_set("last_cleanup_cache", @date("U"), 3600 * self::$files_cleanup_after); } } // self::startDebug(self::$sys,"Check RETURN SYS",__LINE__,__FUNCTION__); return self::$sys['method']; }