static function list_cate($cate = "_cate_all") { $domain = "global"; $kv = new kv($domain); $keys = $kv->allkeys("global"); return $keys; }
/** * 生成和保存密钥对 * @method init * @param boolean $return_pri [返回公钥或者私钥] * @return [string] [公钥或者私钥] * @author NewFuture */ private static function init($return_pri = false) { $res = openssl_pkey_new(); openssl_pkey_export($res, $pri); $d = openssl_pkey_get_details($res); $pub = $d['key']; $time = time() + Config::get('rsa.lifetime') ?: 604800; kv::set('RSA_life_time', $time); kv::set('RSA_pri_key', $pri); Kv::set('RSA_pub_key', $pub); return $return_pri ? $pri : $pub; }
/** * Does nothing for now (with APC), maybe will do something with memcache */ public function __construct(array $APCOptions = null, array $MemcacheOptions = null) { if ($APCOptions && !empty($APCOptions['Enabled']) && (!ini_get('apc.enabled') || !function_exists('apc_store'))) { throw new Exception('APC not available'); } elseif ($APCOptions) { self::$APCOptions = array_merge(self::$DefaultAPCOptions, $APCOptions); self::$APCOn = !empty(self::$APCOptions['Enabled']); } if ($MemcacheOptions && !empty($MemcacheOptions['Enabled']) && !class_exists('Memcached')) { throw new Exception('Memcached not available (Memcached extension, not Memcache)'); } elseif ($MemcacheOptions) { self::$MemcacheOptions = array_merge(self::$DefaultMemcacheOptions, $MemcacheOptions); self::$MemcacheOn = !empty(self::$MemcacheOptions['Enabled']); self::$Memcache = new Memcached(); if (!empty(self::$MemcacheOptions['Consistent'])) { self::$Memcache->setOptions(array(Memcached::OPT_CONNECT_TIMEOUT => 20, Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT, Memcached::OPT_SERVER_FAILURE_LIMIT => 5, Memcached::OPT_REMOVE_FAILED_SERVERS => true, Memcached::OPT_RETRY_TIMEOUT => 1, Memcached::OPT_LIBKETAMA_COMPATIBLE => true)); } $MemcacheServers = self::ParseMemcacheServers(self::$MemcacheOptions['Servers']); self::$Memcache->addServers($MemcacheServers); } }
/** * 处理文件上传 * */ function action_upload() { global $config; global $data; global $tUser; $config["use_layout"] = false; $kv = new kv("sys"); $up = new upfile(UP_PATH . date("Ym"), explode(",", "doc,docx,xls,xlsx,txt,zip,rar,gif,bmp,jpg,png")); $ups = $up->upload($_FILES["up"]); foreach ($ups as $file) { $kv->push("sys.files", $file, $file); $kv->push("user.{$tUser}.files", $file, $file); } $kv->restat_keys("sys.files"); $kv->restat_keys("user.{$tUser}.files"); header("Location:?act=files"); }
//$Servers = [ // '127.0.0.1:11211', 'localhost:11211', '127.0.0.1' //]; $Servers = '127.0.0.1:11211;localhost:11211;127.0.0.1'; try { $KV = new kv(array('Enabled' => false), array('Enabled' => true, 'Servers' => $Servers)); } catch (Exception $E) { echo $E->getMessage(); } // Object style $KV['Value1'] = 'asdf'; echo $KV['Value1']; // Outputs "asdf" echo '<hr />'; // Static class style echo kv::get('Value1'); // Outputs "asdf"; echo '<hr />'; kv::set('Value1', 'qwerty'); echo kv::get('Value1'); // Outputs "qwerty"; echo '<hr />'; kv::clear_all(); echo kv::get('Value1'); // Outputs ""; echo '<hr />'; kv::set('TestNumber', 42); echo $KV['TestNumber']; echo '<hr />'; kv::inc('TestNumber', 2); echo $KV['TestNumber'];