Beispiel #1
0
 public function __construct()
 {
     $this->_memcached = memcache_init();
     $CI =& get_instance();
     $path = $CI->config->item('cache_path');
     $this->_prefixKey = $path == '' ? 'system_cache_' : $path;
 }
Beispiel #2
0
function get_channel_url($uid = null)
{
    if (!is_login()) {
        return false;
    }
    /*
    $channel = new SaeChannel();
    $channel_name = 'NowBoard';
    $duration = 3600;
    $url = $channel->createChannel( wbuid().'.'.$channel_name,$duration);
    */
    if ($uid == null) {
        $uid = wbuid();
    }
    $urlkey = 'nowboard-url-all';
    $mc = memcache_init();
    if (!($url = $mc->get($urlkey))) {
        $channel = new SaeChannel();
        $channel_name = $urlkey;
        $duration = 3600;
        $url = $channel->createChannel($channel_name, $duration);
        $mc->set($urlkey, $url, 0, 3600);
    }
    return $url;
}
Beispiel #3
0
 /**
  * Update/serve a cached file
  *
  * @access	public
  * @param 	object	config class
  * @param 	object	uri class
  * @return	void
  */
 function _display_cache(&$CFG, &$URI)
 {
     $cache_adapter;
     $cach_model = $CFG->item('sae_output_cache');
     $status;
     switch ($cach_model) {
         case '':
             return FALSE;
             break;
         case 'kvdb':
             $cache_adapter = new SaeKV();
             $status = $cache_adapter->init();
             break;
         case 'memcache':
             $cache_adapter = memcache_init();
             $status = $cache_adapter;
             break;
     }
     if (!$status) {
         return FALSE;
     }
     $uri = $CFG->item('base_url') . $CFG->item('index_page') . $URI->uri_string;
     $cache_key = md5($uri);
     $cache = $cache_adapter->get($cache_key);
     if ($cache === FALSE) {
         //缓存已过期
         log_message('debug', "Cache has expired.");
         return FALSE;
     } else {
         //输出缓存
         log_message('debug', "Cache is current. Sending it to browser.");
         $this->_display($cache);
         return TRUE;
     }
 }
Beispiel #4
0
 private function getRights()
 {
     $gid = (int) $_COOKIE['gid'];
     $cacheName = "action_code_group_" . $gid;
     /*$cache = memcache_init();
     		//$cache->init ( array ("dir" => SlightPHP::$appDir . "/cache", "depth" => 3 ) );
     		$rs = $cache->get ( $cacheName );
     		if ($cache and $rs) {
     		} else {
     			$rsObj = base_mAPI::get ( 'm_group', $gid );
     			$rs = $rsObj->get ();
     			$cache->set ( $cacheName, $rs );
     		}*/
     $rsObj = base_mAPI::get('m_group', $gid);
     $rs = $rsObj->get();
     $action = unserialize($rs['action_code']);
     $mc = memcache_init();
     $head_title = $mc->get($_SERVER['HTTP_APPVERSION'] . "head_title");
     if (!$head_title) {
         $modelObj = new base_m();
         $rs = $modelObj->_db->selectOne(base_Constant::TABLE_PREFIX . "system", "", "sysname");
         $head_title = $rs['rsystem_name'];
         $mc->set($_SERVER['HTTP_APPVERSION'] . "head_title", $head_title);
     }
     $this->params['head_title'] = $head_title;
     $this->params['menu'] = $action['menu'];
     $this->params['_userid'] = $_COOKIE['admin_id'];
     $this->params['_adminname'] = $_COOKIE['admin_name'];
 }
Beispiel #5
0
 function __construct($configs)
 {
     $this->cache = \memcache_init();
     if ($this->cache === false) {
         throw new \Exception("SaeMemcache init fail", 1);
     }
 }
Beispiel #6
0
 /**
  * 构造函数,进行模板引擎的实例化操作
  */
 public function __construct()
 {
     if (FALSE == $GLOBALS['G_SP']['view']['enabled']) {
         return FALSE;
     }
     if (FALSE != $GLOBALS['G_SP']['view']['auto_ob_start']) {
         ob_start();
     }
     $this->engine = spClass($GLOBALS['G_SP']['view']['engine_name'], null, $GLOBALS['G_SP']['view']['engine_path']);
     if ($GLOBALS['G_SP']['view']['config'] && is_array($GLOBALS['G_SP']['view']['config'])) {
         $engine_vars = get_class_vars(get_class($this->engine));
         foreach ($GLOBALS['G_SP']['view']['config'] as $key => $value) {
             if (array_key_exists($key, $engine_vars)) {
                 $this->engine->{$key} = $value;
             }
         }
     }
     if (!empty($GLOBALS['G_SP']['sp_app_id']) && isset($this->engine->compile_id)) {
         $this->engine->compile_id = $GLOBALS['G_SP']['sp_app_id'];
     }
     if (empty($this->engine->no_compile_dir)) {
         memcache_init();
     }
     spAddViewFunction('T', array('spView', '__template_T'));
     spAddViewFunction('spUrl', array('spView', '__template_spUrl'));
 }
Beispiel #7
0
function getLoginCookie($openid)
{
    //数据库操作
    require_once 'utils/Mysql.class.php';
    $class_mysqlObj = new Class_mysql();
    $sql_state = "select studentid,IdCard from tb_studentInfo where openid='{$openid}'";
    $studentInfoArr = $class_mysqlObj->query_array($sql_state);
    //取出数据库里的 学号与身份证号
    $studentid = $studentInfoArr[0]['studentid'];
    $IdCard = $studentInfoArr[0]['IdCard'];
    //创建临时文件
    $cookieFile = SAE_TMP_PATH . '/personInfo_cookie.txt';
    $IdCardNum = substr($IdCard, 11, 6);
    if (strlen($IdCard) == 15) {
        $IdCardNum = substr($IdCard, 9, 6);
    }
    $login_url = "http://my.hpu.edu.cn/userPasswordValidate.portal";
    $login = "******";
    $ch = curl_init($login_url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $login);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
    // 把返回来的cookie信息保存在文件中
    curl_exec($ch);
    curl_close($ch);
    //读取文件内容
    $personInfo_cookie = file_get_contents($cookieFile);
    $mmc = memcache_init();
    // 初始化缓存
    memcache_set($mmc, $openid . "personInfo_cookie", $personInfo_cookie, 0, 600);
    return $personInfo_cookie;
}
 public function __construct()
 {
     $this->mem = memcache_init();
     if (false === $this->mem) {
         throw new Gloft_Driver_Cache_Exception("memcached server init error");
     }
 }
Beispiel #9
0
 public static function send($msg, $detail, $level = self::USER, $mobile = null)
 {
     //判断是否定义需要发送短信
     if (!in_array($level, explode(',', C('SMS_LEVEL')))) {
         return;
     }
     //判断发送频率
     $mc = memcache_init();
     $is_send = $mc->get('think_sms_send');
     //如果已经发送,则不发送
     if ($is_send === 'true') {
         $status = 'not send';
     } else {
         //TODU,如果apibus类调整,此类也得调整
         $sms = apibus::init('sms');
         if (is_null($mobile)) {
             $mobile = C('SMS_MOBILE');
         }
         $mc = memcache_init();
         $obj = $sms->send($mobile, mb_substr(C('SMS_SIGN') . $msg, 0, 65, 'utf-8'), "UTF-8");
         if ($sms->isError($obj)) {
             $status = 'failed';
         } else {
             $status = 'success';
             $mc->set('think_sms_send', 'true', 0, C('SMS_INTERVAL'));
         }
     }
     //记录日志
     if (C('LOG_RECORD')) {
         Log::record($msg . ';detail:' . $detail . '【status:' . $status . '】', 'SEND_SMS', true);
     } else {
         Log::write($msg . ';detail:' . $detail . '【status:' . $status . '】', 'SEND_SMS');
     }
 }
Beispiel #10
0
/**
 * 清空缓存
 */
function sp_clear_cache()
{
    import("ORG.Util.Dir");
    $dirs = array();
    // runtime/
    $rootdirs = scandir(RUNTIME_PATH);
    //$noneed_clear=array(".","..","Data");
    $noneed_clear = array(".", "..");
    $rootdirs = array_diff($rootdirs, $noneed_clear);
    foreach ($rootdirs as $dir) {
        if ($dir != "." && $dir != "..") {
            $dir = RUNTIME_PATH . $dir;
            if (is_dir($dir)) {
                array_push($dirs, $dir);
                $tmprootdirs = scandir($dir);
                foreach ($tmprootdirs as $tdir) {
                    if ($tdir != "." && $tdir != "..") {
                        $tdir = $dir . '/' . $tdir;
                        if (is_dir($tdir)) {
                            array_push($dirs, $tdir);
                        }
                    }
                }
            } else {
                @unlink($dir);
            }
        }
    }
    $dirtool = new Dir("");
    foreach ($dirs as $dir) {
        $dirtool->del($dir);
    }
    if (defined('IS_SAE') && IS_SAE) {
        $global_mc = @memcache_init();
        if ($global_mc) {
            $global_mc->flush();
        }
        $no_need_delete = array("THINKCMF_DYNAMIC_CONFIG");
        $kv = new SaeKV();
        // 初始化KVClient对象
        $ret = $kv->init();
        // 循环获取所有key-values
        $ret = $kv->pkrget('', 100);
        while (true) {
            foreach ($ret as $key => $value) {
                if (!in_array($key, $no_need_delete)) {
                    $kv->delete($key);
                }
            }
            end($ret);
            $start_key = key($ret);
            $i = count($ret);
            if ($i < 100) {
                break;
            }
            $ret = $kv->pkrget('', 100, $start_key);
        }
    }
}
Beispiel #11
0
 public function getMemCache()
 {
     if ($this->_cache !== NULL) {
         return $this->_cache;
     } else {
         return $this->_cache = $this->useMemcached ? new Memcached() : @memcache_init();
     }
 }
Beispiel #12
0
 protected function MoveToRoom($strKey, $openID, $roomName)
 {
     $msg = $this->rooms[$roomName]->OnOpen($strKey, $openID);
     $mc = memcache_init();
     $mc->set($openID . 'room', $roomName, 0, 300);
     //记录房间名
     return $msg;
 }
Beispiel #13
0
 function __construct($config = array())
 {
     parent::__construct($config);
     if (defined('IS_SAE')) {
         $this->_mamcache = memcache_init() or trigger_error('Memcache Init Error', E_USER_ERROR);
     } else {
         $this->_mamcache = memcache_connect($this->host, $this->port) or trigger_error('Memcache Connect Error', E_USER_ERROR);
     }
 }
 /**
  * Create a new service repository instance.
  *
  * @param  \Illuminate\Filesystem\Filesystem  $files
  * @param  string  $manifestPath
  * @return void
  */
 public function __construct(Filesystem $files, $manifestPath)
 {
     $this->files = $files;
     $this->manifestPath = $manifestPath;
     $this->isSae = $this->detectSae();
     if ($this->isSae) {
         $this->memcache = memcache_init();
     }
 }
 function __construct()
 {
     $this->mmc = memcache_init();
     //Load filenames
     $arr = self::get($this->fname_key);
     if (is_array($arr)) {
         $this->filenames = $arr;
     }
 }
Beispiel #16
0
 function is_memcache_ok()
 {
     $mmc = @memcache_init();
     if ($mmc == FALSE) {
         return FALSE;
     } else {
         memcache_set($mmc, "dilicms_install_test", "dilicms");
         return memcache_get($mmc, "dilicms_install_test") == 'dilicms';
     }
 }
 private static function initMemcache()
 {
     if (function_exists('memcache_init')) {
         self::$cache = memcache_init();
     } else {
         self::$cache = new Memcache();
         self::$cache->connect(self::$memcacheServer, self::$memcachePort);
     }
     self::$cacheType = 'memcache';
 }
Beispiel #18
0
 public static function get_by_key_name($key_name)
 {
     $link = memcache_init();
     if (!$key_name) {
         return false;
     }
     $data = memcache_get($link, $key_name);
     $new_obj = new Game($key_name, $data);
     return $new_obj;
 }
Beispiel #19
0
 /**
  * 架构函数
  * @access public
  */
 public function __construct()
 {
     if (!function_exists('memcache_init')) {
         throw new Exception('请在SAE平台上运行代码。');
     }
     $this->mc = @memcache_init();
     if (!$this->mc) {
         throw new Exception('您未开通Memcache服务,请在SAE管理平台初始化Memcache服务');
     }
 }
Beispiel #20
0
 static function register_static_delete($key)
 {
     $mmc = memcache_init();
     if ($mmc == false) {
         echo "那个坑爹的Memcache加载失败啦!笨蛋!\n";
     } else {
         memcache_delete($mmc, $key);
         return 1;
     }
 }
Beispiel #21
0
function getTopXiaocao()
{
    $url = "http://www.facejoking.com/api/top/18601/1/1";
    $topXiaocaoArr = getTop($url);
    $mmc = memcache_init();
    /**
     * 把结果存入缓存(参数2:key,参数3:value,参数5:失效时间)
     */
    memcache_set($mmc, "topxiaocao", $topXiaocaoArr, 0, 36000);
    return $topXiaocaoArr;
}
Beispiel #22
0
 public function __construct()
 {
     if (!function_exists('memcache_init')) {
         header('Content-Type:text/html;charset=utf-8');
         exit('请在SAE平台上运行代码。');
     }
     $this->mc = @memcache_init();
     if (!$this->mc) {
         header('Content-Type:text/html;charset=utf-8');
         exit('您未开通Memcache服务,请在SAE管理平台初始化Memcache服务');
     }
 }
Beispiel #23
0
 * @package  Extend
 * @subpackage  Driver.Cache
 * @author    liu21st <*****@*****.**>
 */
class Memcachesae extends Cache
{
    /**
     * 架构函数
     * @param array $options 缓存参数
     * @access public
     */
    function __construct($options = array())
    {
Beispiel #24
0
 function pagesetting($inPath)
 {
     $modelObj = new base_m();
     $mc = memcache_init();
     if (!$_POST) {
         $system_name = $mc->get($_SERVER['HTTP_APPVERSION'] . "head_title");
         $this->params['system_name'] = $system_name ? $system_name : base_Constant::DEFAULT_TITLE;
         //$this->params ['rewrite'] =(int)base_Constant::REWRITE;
         //$this->params ['cookie_key'] =base_Constant::COOKIE_KEY;
         //$this->params ['temp_dir'] =base_Constant::TEMP_DIR;
     } else {
         //$this->showMsg("SAE平台暂不提供修改功能!");
         if ($_POST['cleartable'] == 1) {
             $tableArr = array("category", "goods", "member", "purchase", "sales", "log");
             if (!$modelObj->clearTable($tableArr)) {
                 $this->showMsg("清空数据出错!原因:" . $modelObj->getError());
             }
         }
         $system_name = base_Utils::getStr($_POST['system_name']);
         $modelObj->_db->delete(base_Constant::TABLE_PREFIX . "system");
         $modelObj->_db->insert(base_Constant::TABLE_PREFIX . "system", array("sysname" => $system_name, "options" => ""));
         $mc->set($_SERVER['HTTP_APPVERSION'] . "head_title", $system_name);
         $this->showMsg("修改成功", $this->createUrl("/system/setting"), 2, 1);
         exit;
         $constant = file_get_contents(ROOT_APP . "/base/Constant.class.php");
         $system_name = base_Utils::getStr($_POST['system_name']);
         if ($system_name) {
             $constant = str_replace(base_Constant::DEFAULT_TITLE, $system_name, $constant);
         }
         $cookie_key = base_Utils::getStr($_POST['cookie_key']);
         if ($cookie_key != base_Constant::COOKIE_KEY) {
             $cookie_key = md5($cookie_key);
             $constant = str_replace(base_Constant::COOKIE_KEY, $cookie_key, $constant);
         }
         $rewrite = base_Utils::getStr($_POST['rewrite'], 'int');
         if ($rewrite == 1) {
             $constant = str_replace("FALSE", "TRUE", $constant);
         } else {
             $constant = str_replace("TRUE", "FALSE", $constant);
         }
         $f = @fopen(ROOT_APP . "/base/Constant.class.php", "r+");
         if ($f) {
             fwrite($f, $constant);
             fclose($f);
         } else {
             $this->ShowMsg("没有写权限");
         }
         $this->showMsg("修改成功", $this->createUrl("/system/setting"), 2, 1);
         //$this->redirect($this->createUrl("/system/setting"));
     }
     return $this->render('system/setting.html', $this->params);
 }
Beispiel #25
0
 /**
  * 重设缓存
  */
 public function resetCache()
 {
     if ($this->config->cacheMode == 'Mysql') {
         #1.Mysql模式
         $table = $this->db->getPrefix() . self::$tableName;
         $this->db->query("TRUNCATE TABLE {$table} ");
     } else {
         #2.SAE模式
         $mc = memcache_init();
         memcache_flush($mc);
     }
     $this->request->throwJson('success');
 }
Beispiel #26
0
 /**
  * 架构函数
  * @param array $options 缓存参数
  * @access public
  */
 public function __construct($options = [])
 {
     if (!function_exists('memcache_init')) {
         throw new Exception('请在SAE平台上运行代码。');
     }
     $this->handler = memcache_init();
     if (!$this->handler) {
         throw new Exception('您未开通Memcache服务,请在SAE管理平台初始化Memcache服务');
     }
     if (!empty($options)) {
         $this->options = array_merge($this->options, $options);
     }
 }
Beispiel #27
0
 public function __construct($cacheName = null)
 {
     if ($cacheName) {
         $this->cacheName = $cacheName;
     }
     $this->cacheTimeKey = $this->cacheName . '-time';
     if (defined('SAE_APPNAME')) {
         $this->mc = memcache_init();
     } else {
         $this->mc = new Memcache();
         $this->mc->connect('localhost', 11211) or die("Could not connect");
     }
 }
 /**
 +----------------------------------------------------------
 * 架构函数
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 */
 function __construct($options = '')
 {
     //[sae] 下不用判断memcache模块是否存在
     // if ( !extension_loaded('memcache') ) {
     //     throw_exception(L('_NOT_SUPPERT_').':memcache');
     // }
     if (empty($options)) {
         $options = array('host' => C('MEMCACHE_HOST') ? C('MEMCACHE_HOST') : '127.0.0.1', 'port' => C('MEMCACHE_PORT') ? C('MEMCACHE_PORT') : 11211, 'expire' => C('DATA_CACHE_TIME'), 'length' => 0);
     }
     $this->options = $options;
     $this->handler = memcache_init();
     //[sae],实例化memcache
 }
 /**
  * Update/serve a cached file
  *
  * @access  public
  * @param   object  config class
  * @param   object  uri class
  * @return  void
  */
 function _display_cache(&$CFG, &$URI)
 {
     $path = $CFG->item('cache_path');
     $prefixKey = $path == '' ? 'system_cache_' : $path;
     $cache_adapter = null;
     $cache_model = $CFG->item('sae_output_cache');
     switch ($cache_model) {
         case '':
             return FALSE;
             break;
         case 'kvdb':
             $cache_adapter = new SaeKV();
             $status = $cache_adapter->init();
             break;
         case 'memcache':
             $cache_adapter = memcache_init();
             $status = $cache_adapter;
             break;
     }
     if (!$status) {
         return FALSE;
     }
     $uri = $CFG->item('base_url') . $CFG->item('index_page') . $URI->uri_string;
     $cache_key = md5($uri);
     $cache = $cache_adapter->get($prefixKey . $cache_key);
     if ($cache === FALSE) {
         //缓存已过期
         log_message('debug', "Cache has expired.");
         return FALSE;
     } else {
         if ($cache_model == 'kvdb') {
             $stored = unserialize($cache);
             if ($stored['ttl'] > 0) {
                 if (time() > $stored['time'] + $stored['ttl']) {
                     $cache_adapter->delete($prefixKey . $cache_key);
                     log_message('debug', "Cache has expired.");
                     return FALSE;
                 }
             }
             $cache = $stored['data'];
         } else {
             if ($cache_model == 'memcache') {
                 $cache = $cache[0];
             }
         }
         //输出缓存
         log_message('debug', "Cache is current. Sending it to browser.");
         $this->_display($cache);
         return TRUE;
     }
 }
Beispiel #30
0
function getLocation($openid)
{
    $mmc = memcache_init();
    if ($mmc == true) {
        $location = memcache_get($mmc, $openid);
        if (!empty($location)) {
            return json_decode($location, true);
        } else {
            return "请先发送位置给我!\n点击底部的'+'号,再选择'位置',等地图显示出来以后,点击'发送'";
        }
    } else {
        return "未启用缓存,请先开启服务器的缓存功能。";
    }
}