Example #1
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;
}
function db_mysqli_query_fetch_list($mysqli, $query, $MYSQLI_TYPE)
{
    $config = getConfig();
    $params = $config['memcache'];
    $memcache = memcache_connect($params['host'], $params['port']);
    $memcacheQueryKey = 'QUERY' . $query['slow'];
    $data = memcache_get($memcache, $memcacheQueryKey);
    if (!empty($data)) {
    } else {
        if (!empty($query['fast'])) {
            $result = mysqli_query($mysqli, $query['fast']);
        } else {
            $result = mysqli_query($mysqli, $query['slow']);
        }
        $data = [];
        while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
            $data[] = $row;
        }
        //another proc
        /* $pid = pcntl_fork();
           if ($pid == 0) {*/
        memcache_set($memcache, $memcacheQueryKey, $data, 0, 60 * 10);
        /*    posix_kill(posix_getpid(), SIGTERM);
              }*/
    }
    memcache_close($memcache);
    return $data;
}
Example #3
0
 public function set($key, $value)
 {
     $this->check();
     if (memcache_set($this->connection, $key, $value, 0, Config::Get('cache_time')) === false) {
         throw new CacheException("Couldn't store data in cache");
     }
 }
Example #4
0
 public static function set($key, $value, $name = 'default')
 {
     if (!App::instance()->get('cache_enable')) {
         return FALSE;
     }
     $client = self::client($key, $name);
     $ndx = self::$prefix . '_' . $key;
     $time = microtime(TRUE);
     // if ($cached = self::exist($key)){
     //     list($time, $ttl) = $cached;
     // }
     $data = App::instance()->serialize(array($value, $time, self::$ttl));
     switch (self::$engine) {
         case 'apc':
             return apc_store($ndx, $data, self::$ttl);
         case 'redis':
             // return $client->set($ndx, $data, array('ex' => self::$ttl));
             if (self::$ttl > 0) {
                 return $client->setex($ndx, self::$ttl, $data);
             } else {
                 return $client->set($ndx, $data);
             }
             break;
         case 'memcache':
             return memcache_set($client, $ndx, $data, 0, self::$ttl);
             break;
         default:
             return App::instance()->write($client . DS . $ndx, $data);
     }
     return FALSE;
 }
Example #5
0
 public function setItem($key, $value)
 {
     if (empty($key)) {
         throw new CacheException('CACHE ERROR:key is empty');
     }
     return memcache_set($this->cache, $key, $value, self::COMP, $this->ttl);
 }
Example #6
0
 public function requeue_snapshot()
 {
     ignore_user_abort(true);
     header("Connection: Close");
     flush();
     ob_end_flush();
     $m = memcache_connect('127.0.0.1', 11211);
     $urlkey = sha1($this->snapshot_url);
     if (isset($_GET['requeue']) && 'true' != $_GET['requeue']) {
         if (memcache_get($m, $urlkey)) {
             die;
         }
     }
     memcache_set($m, $urlkey, 1, 0, 300);
     $requeue_url = self::renderer . "/queue?url=" . rawurlencode($this->snapshot_url) . "&f=" . urlencode($this->snapshot_file);
     $retval = file_get_contents($requeue_url);
     $tries = 1;
     while (false === $retval && $tries <= 5) {
         sleep(1);
         // in the event that the failed call is due to a mShots.js service restart,
         // we need to be a little patient as the service comes back up
         $retval = file_get_contents($requeue_url);
         $tries++;
     }
 }
Example #7
0
 public function removeObserver($conn)
 {
     if (isset($conn->token)) {
         $token = $conn->token;
         if (defined("PUBSUB_CHANNEL")) {
             $observers = memcache_get($this->mmc, 'channel.observers.' . (string) $token->user_id);
             if (!empty($observers)) {
                 $observers = unserialize($observers);
                 foreach ($observers as $key => $value) {
                     if ($conn->_connection_identifier == $value->_connection_identifier) {
                         unset($observers[$key]);
                         memcache_set($this->mmc, 'channel.observers.' . (string) $token->user_id, serialize($observers));
                         return true;
                     }
                 }
             }
         } else {
             if (isset($this->observers[(string) $token->user_id])) {
                 foreach ($this->observers[(string) $token->user_id] as $key => $value) {
                     if ($conn == $value) {
                         unset($this->observers[(string) $token->user_id][$key]);
                         return true;
                     }
                 }
             }
         }
     }
     return false;
 }
 function pmxCachePut($key, $value, $ttl, $useMember = false, $cleaner = null)
 {
     global $PortaMx_cache, $user_info, $mcache;
     $st = microtime(true);
     $ckey = $PortaMx_cache['key'] . ($useMember ? '-' . implode('_', $user_info['groups']) : '') . '-' . $key;
     if ($value !== null) {
         $value = serialize($value);
     } else {
         if ($cleaner !== null && $useMember) {
             $ckey = $PortaMx_cache['key'] . '-' . $cleaner . '-' . $key;
         }
     }
     // connected?
     if (empty($mcache)) {
         connect_mcache();
     }
     if ($mcache) {
         memcache_set($mcache, $ckey, $value, 0, $ttl);
         if ($value !== null) {
             $PortaMx_cache['vals']['saved'] += strlen($value);
         }
         $PortaMx_cache['vals']['time'] += microtime(true) - $st;
     }
     // handle member groups key?
     if ($useMember && $cleaner === null) {
         pmxCacheMemGroupAcs();
     }
 }
Example #9
0
 public function insert($key = '', $var = '', $time = 60, $compressed = false)
 {
     if ($compressed !== true) {
         $var = array($var, time(), $time);
     }
     return memcache_set($key, $var, 0, $time);
 }
Example #10
0
function pdb_get_data($key, $provider, $arguments = [])
{
    $mc_handler = memcache_pconnect(MC_HOST);
    $value = memcache_get($mc_handler, $key);
    if ($value !== false) {
        return $value;
    } else {
        $locking_key = 'lock_' . $key;
        $locking_value = microtime(true);
        for ($i = 0; $i < MC_LOCK_DELAY * 1000 / MC_SLEEP_TIME + 1; $i++) {
            $lock = memcache_add($mc_handler, $locking_key, $locking_value, 0, MC_LOCK_DELAY);
            if ($lock) {
                $value = call_user_func_array($provider, $arguments);
                memcache_set($mc_handler, $key, $value);
                memcache_delete($mc_handler, $locking_key);
                return $value;
            } else {
                usleep(MC_SLEEP_TIME);
                $value = memcache_get($mc_handler, $key);
                if ($value != false) {
                    return $value;
                }
            }
        }
    }
    return call_user_func_array($provider, $arguments);
}
Example #11
0
 /**
  *	Store value in cache
  *	@return mixed|FALSE
  *	@param $key string
  *	@param $val mixed
  *	@param $ttl int
  **/
 function set($key, $val, $ttl = 0)
 {
     $fw = Base::instance();
     if (!$this->dsn) {
         return TRUE;
     }
     $ndx = $this->prefix . '.' . $key;
     $time = microtime(TRUE);
     if ($cached = $this->exists($key)) {
         list($time, $ttl) = $cached;
     }
     $data = $fw->serialize(array($val, $time, $ttl));
     $parts = explode('=', $this->dsn, 2);
     switch ($parts[0]) {
         case 'apc':
         case 'apcu':
             return apc_store($ndx, $data, $ttl);
         case 'redis':
             return $this->ref->set($ndx, $data, array('ex' => $ttl));
         case 'memcache':
             return memcache_set($this->ref, $ndx, $data, 0, $ttl);
         case 'wincache':
             return wincache_ucache_set($ndx, $data, $ttl);
         case 'xcache':
             return xcache_set($ndx, $data, $ttl);
         case 'folder':
             return $fw->write($parts[1] . $ndx, $data);
     }
     return FALSE;
 }
Example #12
0
 public function set($name, $data, $ttl = 86400)
 {
     if (!is_resource($this->memcache)) {
         throw new \Exception("Memcached can't connect.");
     }
     return memcache_set($this->memcache, $name, $data, 0, $ttl);
 }
Example #13
0
 public function insert($key, $var, $time, $compressed)
 {
     if ($compressed !== true) {
         $var = [$var, time(), $time];
     }
     return memcache_set($key, $var, 0, $time);
 }
Example #14
0
function cache_set($key, $data, $expires)
{
    $connection = cache_connect();
    $res = memcache_set($connection, (string) $key, $data, false, (int) $expires);
    memcache_close($connection);
    return $res;
}
Example #15
0
 function setValue($key, $value, $expire = 0)
 {
     if ($expire == 0) {
         memcache_set($this->mmc, $key, $value);
     } else {
         memcache_set($this->mmc, $key, $value, $expire);
     }
 }
Example #16
0
 /**
  * 存放值
  *
  * @param mixed $key
  * @param mixed $var
  * @param mixed $flag   默认为0不压缩  压缩状态填写:MEMCACHE_COMPRESSED
  * @param mixed $expire  默认缓存时间(单位秒)
  */
 public function set($key, $var, $flag = 0, $expire = 10)
 {
     $f = @memcache_set($this->memcache, $key, $var, $flag, $expire);
     if (empty($f)) {
         die('memcache set error');
     } else {
         return TRUE;
     }
 }
Example #17
0
function memcache_version_set($memcache_obj, $key, $value, $flag, $ttl)
{
    global $config;
    if ($config['mcache']['version'] == 0) {
        return memcache_set($memcache_obj, $key, $value, $flag, $ttl);
    } else {
        return $memcache_obj->set($key, $value, $ttl);
    }
}
Example #18
0
 static function register_static_set($key, $value)
 {
     $mmc = memcache_init();
     if ($mmc == false) {
         echo "那个坑爹的Memcache加载失败啦!笨蛋!\n";
     } else {
         memcache_set($mmc, 'tk_' . $key, $value);
     }
 }
Example #19
0
File: cache.php Project: senko/rfx
function cache_set($key, $val, $expire = false)
{
    global $_mch;
    if ($expire) {
        memcache_set($_mch, $key, serialize($val), 0, $expire);
    } else {
        memcache_set($_mch, $key, serialize($val));
    }
}
Example #20
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';
     }
 }
Example #21
0
function memcache_replace($obj, $key, $var, $flag = false, $expire = 0)
{
    $key = rKey($key);
    if (file_exists(cDir . $key . ext . extT)) {
        if (!empty($var)) {
            return memcache_set($obj, $key, $var, $flag, $expire);
        }
        return memcache_delete($obj, $key);
    }
    return false;
}
Example #22
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;
}
Example #23
0
function setLocation($openid, $locationX, $locationY)
{
    $mmc = memcache_init();
    if ($mmc == true) {
        $location = array("locationX" => $locationX, "locationY" => $locationY);
        memcache_set($mmc, $openid, json_encode($location), 60);
        return "您的位置已缓存。\n现在可发送“附近”加目标的命令,如“附近酒店”,“附近加油站”。";
    } else {
        return "未启用缓存,请先开启服务器的缓存功能。";
    }
}
Example #24
0
function send_email_alert($name, $title, $message, $t = 10)
{
    //	debuglog(__FUNCTION__);
    $last = memcache_get(controller()->memcache->memcache, "last_email_sent_{$name}");
    if ($last + $t * 60 > time()) {
        return;
    }
    debuglog("mail('" . YAAMP_ADMIN_EMAIL . "', {$title}, ...)");
    $b = mail(YAAMP_ADMIN_EMAIL, $title, $message);
    if (!$b) {
        debuglog('error sending email');
    }
    memcache_set(controller()->memcache->memcache, "last_email_sent_{$name}", time());
}
Example #25
0
function setRamCache($key, $data, $depo)
{
    if ($depo == 'ram_eaccelerator') {
        return eaccelerator_put($key, $data);
    }
    if ($depo == 'ram_xcache') {
        return xcache_set($key, $data);
    }
    if ($depo == 'ram_memcache') {
        $memcache_obj = memcache_connect('127.0.0.1', '11211');
        return memcache_set($memcache_obj, $key, $data, 0, 86400);
    }
    return false;
}
Example #26
0
 public function add_monitoring_function($name, $d1)
 {
     return;
     $count = memcache_get($this->memcache, "{$name}-count");
     memcache_set($this->memcache, "{$name}-count", $count + 1);
     $d = memcache_get($this->memcache, "{$name}-time");
     memcache_set($this->memcache, "{$name}-time", $d + $d1);
     $a = memcache_get($this->memcache, 'url-map');
     if (!$a) {
         $a = array();
     }
     $a[$name] = $count + 1;
     memcache_set($this->memcache, 'url-map', $a);
 }
 public function getMetaData($meta_page)
 {
     $mc = memcache_connect('185.87.49.111', 11211);
     $key = 'getMetaData' . $meta_page;
     if (memcache_get($mc, $key)) {
         return $result = memcache_get($mc, $key);
     } else {
         $db = Db::GetConnection();
         $query = $db->prepare("SELECT meta_title, meta_keywords, meta_description FROM metadata WHERE meta_page = :meta_page;");
         $query->execute(array('meta_page' => "{$meta_page}"));
         $result = $query->fetch();
         memcache_set($mc, $key, $result, MEMCACHE_COMPRESSED, 60 * 60);
         return $result;
     }
 }
Example #28
0
/**
 * 加载目标网站图片验证码
 * @param string $authcode_url 目标网站验证码地址
 */
function showAuthcode($authcode_url, $openid)
{
    //创建临时文件
    $cookieFile = SAE_TMP_PATH . '/jw_cookie.txt';
    $ch = curl_init($authcode_url);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
    // 把返回来的cookie信息保存在文件中
    curl_exec($ch);
    curl_close($ch);
    //读取文件内容
    $jw_cookie = file_get_contents($cookieFile);
    $mmc = memcache_init();
    // 初始化缓存
    /**
     * 把文件内容存入缓存(参数2:key,参数3:value,参数5:失效时间)
     */
    memcache_set($mmc, $openid . "jw_cookie", $jw_cookie, 0, 300);
}
Example #29
0
 static function do_put($key, $value, $expire_time = 0)
 {
     if (self::connect()) {
         $result = memcache_replace(CGlobal::$memcache_connect_id, md5(AZMemcache::$identifier . $key), $value, MEMCACHE_COMPRESSED, (int) $expire_time);
         if ($result == false) {
             if (DEBUG) {
                 self::$set++;
                 CGlobal::$query_debug .= "<table width='95%' border='1' cellpadding='6' cellspacing='0' bgcolor='#FEFEFE'  align='center'>\r\n\t\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t <td style='font-size:14px' bgcolor='#EFEFEF'><span style='color:blue'><b>Memcache</b></span></td>\r\n\t\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t\t <td style='font-family:courier, monaco, arial;font-size:14px;color:brown'>Set \"{$key}\" (Expire: " . ($expire_time ? "{$expire_time}  sec" : " forever") . ") by memcache_set(" . md5(AZMemcache::$identifier . $key) . ");</td>\r\n\t\t\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t\t<td style='font-size:14px' bgcolor='#EFEFEF'></td>\r\n\t\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t       </table><br />\n\n";
             }
             $result = memcache_set(CGlobal::$memcache_connect_id, md5(AZMemcache::$identifier . $key), $value, MEMCACHE_COMPRESSED, (int) $expire_time);
         } elseif (DEBUG) {
             self::$replace++;
             CGlobal::$query_debug .= "<table width='95%' border='1' cellpadding='6' cellspacing='0' bgcolor='#FEFEFE'  align='center'>\r\n\t\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t <td style='font-size:14px' bgcolor='#EFEFEF'><span style='color:blue'><b>Memcache</b></span></td>\r\n\t\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t\t <td style='font-family:courier, monaco, arial;font-size:14px;color:brown'>Replace \"{$key}\" (Expire: " . ($expire_time ? "{$expire_time}  sec" : " forever") . ") by memcache_set(" . md5(AZMemcache::$identifier . $key) . ");</td>\r\n\t\t\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t\t<td style='font-size:14px' bgcolor='#EFEFEF'></td>\r\n\t\t\t\t\t\t\t</tr>\r\n\t\t\t\t\t\t       </table><br />\n\n";
         }
         return $result;
     }
     return false;
 }
 public function set($key, $data, $expire)
 {
     if (FALSE == $this->mc) {
         if (FALSE == $this->connect()) {
             return FALSE;
         }
     }
     $key = $this->keys_prefix . $key;
     if ($this->debug_mode) {
         $time = microtime(TRUE);
         $res = memcache_set($this->mc, $key, $data, NULL, $expire);
         $time = microtime(TRUE) - $time;
         $this->debug_info->time += $time;
         $this->debug_info->queries[] = (object) array('action' => 'SET', 'key' => $key, 'result' => $res ? 'TRUE' : 'FALSE', 'time' => number_format($time, 5, '.', ''));
         return $res;
     }
     return memcache_set($this->mc, $key, $data, NULL, $expire);
 }