Example #1
0
function getCache($key)
{
    global $memcache;
    initCache();
    if (!$memcache) {
        return null;
    }
    $ret = memcache_get($memcache, $key);
    if ($ret !== null) {
        try {
            global $counter;
            initCounter();
            $counter->incr('cachehit');
        } catch (Exception $e) {
        }
    }
    return $ret;
}
Example #2
0
<?php

//require('./init.php');
require './getwalltypes.php';
global $counter;
initCounter();
var_dump('resetcounter: ' . $counter->set('cachehit', 0));
echo 'cachehit: ' . $counter->get('cachehit') . "\r\n";
var_dump('resetcounter: ' . $counter->set('dbhit', 0));
echo 'dbhit: ' . $counter->get('dbhit') . "\r\n";
if (!$counter->exists('usercount')) {
    var_dump($counter->create('usercount'));
}
//var_dump('resetcounter: ' . $counter -> set('usercount', 0));
echo $counter->get('usercount') . "\r\n";
/*
 * Msg debugging
echo "create\r\n";
$id1 = WaMsg::CreateMsg(1, 2, 'aa', false);
$id2 = WaMsg::CreateMsg(3, 2, 'aab', false);
echo "findall and get \r\n";
var_dump(WaMsg::FindMsgIdsByUser(2, 1));
var_dump(WaMsg::GetMsgInfo($id1));
echo "getunread setread and getunread";
var_dump(WaMsg::FindMsgIdsByUserUnread(2));
var_dump(WaMsg::SetMsgRead($id2));
var_dump(WaMsg::FindMsgIdsByUserUnread(2));
echo "delete\r\n";
var_dump(WaMsg::DeleteMsg($id2, 2));
var_dump(WaMsg::DeleteMsg($id2, 3));
var_dump(WaMsg::FindMsgIdsByUserUnread(2));
Example #3
0
function createWall($name, $desc, $walltype)
{
    global $loginUser;
    if (!$loginUser) {
        returnError('请先登录。');
        return;
    }
    try {
        $userData = WaUser::GetUserData($loginUser);
        if (!$userData) {
            throw new Exception('获取用户失败。');
        }
    } catch (Exception $e) {
        returnError($e->getMessage());
        return;
    }
    $wealth = $userData['user_wealth'];
    if ($wealth < 30) {
        returnError('墙砖不够。');
        return;
    }
    try {
        $id = WaWall::CreateWall($loginUser, $name, $desc, $walltype, 5);
    } catch (Exception $e) {
        returnError($e->getMessage());
        return;
    }
    $userData['user_wealth'] -= 30;
    $userData['user_exp'] += 20;
    try {
        $ret = WaUser::SetUserData($loginUser, $userData);
        if (!$ret) {
            throw new Exception('扣墙砖失败。');
        }
    } catch (Exception $e) {
        returnError($e->getMessage());
        return;
    }
    global $counter;
    initCounter();
    $counter->incr('wallcount');
    $ret = array('state' => 'success', 'wall_id' => $id);
    echo json_encode($ret);
}