Esempio n. 1
0
function sqlGet($query)
{
    $result = cacheGet($query);
    if ($result !== false) {
        #echo "<b>Попадание в кеш:</b> $query<br>";
        #echo $result;
        return $result;
    } else {
        #echo "<b>Кеш не сработал:</b> $query<br>";
        $resource = sqlQuery($query);
        #$result = array();
        while ($row = mysql_fetch_assoc($resource)) {
            $result[] = $row;
        }
        cacheSet($query, $result, 3600);
        #echo $resource;
        return $result;
    }
}
Esempio n. 2
0
}
function dbExec($db, $sql)
{
    $rs = $db->Execute($sql);
    if (!$rs) {
        p_sqlfail($db, $sql);
    }
    return $rs;
}
if (false) {
    // xxx avoid the select id from call
    $uk = "{$username}-{$password}";
    $uid = cacheGet($uk);
    if (!$uid) {
        $uid = $db->GetOne("select id from users where username=\"{$username}\" and password=\"{$password}\"");
        cacheSet($uk, $uid, 3600);
    }
} else {
    $uid = $db->GetOne("select id from users where username=\"{$username}\" and password=\"{$password}\"");
}
if ($uid == "") {
    echo __LINE__ . " ERROR\n";
    dbgt("username/password lookup failed");
    exit;
}
if (false) {
    // xxx avoid the $db->MetaColumns call
} else {
    $mc = $db->MetaColumns($t);
    $fld = $mc[strtoupper($c)];
    $type = $fld->type;
 }
 if (!is_file("inc/language/" . $cfg["language_file"])) {
     $cfg["language_file"] = $cfg["default_language"];
 }
 // load per user settings
 // activated ?
 if ($cfg["enable_personal_settings"] == 1) {
     loadUserSettingsToConfig($cfg["uid"]);
 }
 $cfg["theme"] = CheckandSetUserTheme();
 // theme
 require_once "themes/" . $cfg["theme"] . "/index.php";
 // load language
 loadLanguageFile($cfg["language_file"]);
 // set cache
 cacheSet($currentUser);
 // login-tasks
 if (!isset($_SESSION['login_tasks'])) {
     // check main-directories.
     checkMainDirectories();
     // maintenance-run
     require_once "inc/classes/MaintenanceAndRepair.php";
     MaintenanceAndRepair::maintenance(MAINTENANCEANDREPAIR_TYPE_STD);
     $_SESSION['next_int_maintenance'] = null;
     // set flag
     $_SESSION['login_tasks'] = 1;
 }
 // set transfers-cache
 cacheTransfersSet();
 // set session-settings
 $_SESSION['settings']['index_meta_refresh'] = $cfg["enable_index_meta_refresh"] != 0 ? 1 : 0;
Esempio n. 4
0
 private function doTb($tid, $cid = 0)
 {
     if ($tid == 2610) {
         //彩票部分
         $cacheId = 'doTb_' . $tid;
         $fcurl = cacheGet($cacheId);
         if (empty($fcurl)) {
             $url = 'http://www.114la.com/icai.json';
             $fcurl = XUtils::fcurl($url);
             cacheSet($cacheId, $fcurl, 3600);
         }
         $fcurl = substr($fcurl, 17, -1);
         $data_arr = json_decode($fcurl, TRUE);
         if (!empty($data_arr)) {
             //对应关系
             $dy = array('ssq' => array(220, 221, 222), 'dlt' => array(223, 224, 225), 'fc3d' => array(226, 227, 228), 'jx_11x5' => array(229, 230, 231));
             foreach ($data_arr as $tp => $v) {
                 $va = $v[0];
                 $fdata[$dy[$tp][0]] = array(0 => array('title' => '上期开奖号码', 'link' => $va['url'][0], 'opt_a' => implode(',', $va['result']), 'opt_b' => $va['phase'], 'opt_c' => $va['date']));
                 $fdata[$dy[$tp][1]] = array(0 => array('title' => '立即投注', 'link' => $va['url'][1]), 1 => array('title' => $va['chain'][0], 'link' => $va['chain'][1]));
                 foreach ($va['link'] as $vl => $tu) {
                     $tu['link'] = $tu['url'];
                     unset($tu['url']);
                     $va['link'][$vl] = $tu;
                 }
                 $fdata[$dy[$tp][2]] = $va['link'];
             }
         }
         if (!empty($fdata)) {
             foreach ($fdata as $cid => $cinfo) {
                 Links::model()->deleteAll("catalog_id=:cid", array(':cid' => $cid));
                 foreach ($cinfo as $info) {
                     try {
                         $model = new Links();
                         $info['catalog_id'] = $cid;
                         $info['title'] = empty($info['title']) ? '待定' : $info['title'];
                         $info['link'] = empty($info['link']) || $info['link'] == '#' ? 'http://www.114la.com/' : $info['link'];
                         $info['mix'] = empty($info['mix']) ? null : base64_decode($info['mix']);
                         $info = array_filter($info);
                         $model->attributes = $this->_form($info);
                         //                        ppr($model->attributes);
                         $model->save();
                     } catch (Exception $exc) {
                         return 'error1caipiao';
                     }
                 }
             }
         }
         return 'ok';
         //            ppr($fdata,1);
     } elseif ($tid == 1114) {
         //实时热点部分
         $cacheId = 'doTb_' . $tid;
         $fcurl = cacheGet($cacheId);
         if (empty($fcurl)) {
             $url = 'http://api4.114la.com/1114_2.json';
             $fcurl = XUtils::fcurl($url);
             cacheSet($cacheId, $fcurl, 3600);
         }
         $fcurl = substr($fcurl, 20, -1);
         //            ppr($fcurl,1);
         if (!empty($fcurl) && ($fcurl = json_decode($fcurl, 1))) {
             //先将对应的旧数据处理
             $old = reqPost('old');
             if (empty($old)) {
                 Links::model()->updateAll(array('status_is' => 'N'), "`catalog_id`='{$cid}'");
             } else {
                 Links::model()->deleteAll("catalog_id=:cid", array(':cid' => $cid));
             }
             //                ppr(Links::model()->findAll("`catalog_id`='$cid'"));
             foreach ($fcurl as $info) {
                 try {
                     $model = new Links();
                     $info['catalog_id'] = $cid;
                     $info['title'] = empty($info['title']) ? '待定' : $info['title'];
                     $info['link'] = empty($info['url']) || $info['url'] == '#' ? 'http://www.114la.com/' : $info['url'];
                     unset($info['url']);
                     $info = array_filter($info);
                     $model->attributes = $this->_form($info);
                     //                        ppr($model->attributes);
                     $model->save();
                 } catch (Exception $exc) {
                     return 'error1';
                 }
             }
             $cacheId = '_catalogAllNum';
             $catalogAllNum = XXcache::refresh($cacheId);
             return empty($catalogAllNum[$cid]) ? 0 : $catalogAllNum[$cid] . ' ok';
         } else {
             return 'error2';
         }
         ppr($data_arr, 1);
     } elseif ($tid > 1000 && $tid < 10000) {
         $tid = (int) $tid;
         $data = $re = 0;
         $cacheId = 'doTb_' . $tid;
         $fcurl = cacheGet($cacheId);
         if (empty($fcurl)) {
             $url = 'http://www.114la.com/api/ky.php?id=' . $tid . '&' . time();
             //                $url = 'http://www.114la.com/api/ky.php?id='.$tid;
             $fcurl = XUtils::fcurl($url);
             cacheSet($cacheId, $fcurl, 3600);
         }
         if (!empty($fcurl) && ($fcurl = json_decode($fcurl, 1))) {
             //先将对应的旧数据处理
             $old = reqPost('old');
             if (empty($old)) {
                 Links::model()->updateAll(array('status_is' => 'N'), "`catalog_id`='{$cid}'");
             } else {
                 Links::model()->deleteAll("catalog_id=:cid", array(':cid' => $cid));
             }
             //                ppr(Links::model()->findAll("`catalog_id`='$cid'"));
             foreach ($fcurl as $info) {
                 try {
                     $model = new Links();
                     $info['catalog_id'] = $cid;
                     $info['title'] = empty($info['title']) ? '待定' : $info['title'];
                     $info['link'] = empty($info['link']) || $info['link'] == '#' ? 'http://www.114la.com/' : $info['link'];
                     $info['mix'] = empty($info['mix']) ? null : base64_decode($info['mix']);
                     $info = array_filter($info);
                     $model->attributes = $this->_form($info);
                     //                        ppr($model->attributes);
                     $model->save();
                 } catch (Exception $exc) {
                     return 'error1';
                 }
             }
             $cacheId = '_catalogAllNum';
             $catalogAllNum = XXcache::refresh($cacheId);
             return empty($catalogAllNum[$cid]) ? 0 : $catalogAllNum[$cid] . ' ok';
         } else {
             return 'error2';
         }
     } else {
         return 'error3';
     }
 }
/**
 * Renvoie la dernière version de WordPress
 */
function getWordPressVersion()
{
    $fileCache = 'wordpress';
    if (cacheState($fileCache, gCACHE_TIME_WORDPRESS) === FALSE) {
        $urlAPI = gWORDPRESS_API_CORE;
        $json = join('', file($urlAPI));
        $infos = json_decode($json, TRUE);
        cacheSet($fileCache, $infos);
    } else {
        $infos = cacheGet($fileCache);
    }
    return $infos;
}
Esempio n. 6
0
function getconfig()
{
    global $config, $dbg;
    if (false) {
        $o = cacheGet("vtc.config");
        if (!$o) {
            //dbg("fetching config ...");
            $config = array();
            $rs = dbExec("select * from config");
            while ($o = $rs->FetchNextObj()) {
                $config[$o->tag] = $o->val;
            }
            cacheSet("vtc.config", $config, 10);
        } else {
            //dbg("returning cached config ...");
            $config = array();
            foreach ($o as $k => $v) {
                $config[$k] = $v;
            }
        }
    } else {
        $config = array();
        $rs = dbExec("select * from config");
        while ($o = $rs->FetchNextObj()) {
            $config[$o->tag] = $o->val;
        }
    }
    //dbg($config);
}
Esempio n. 7
0
        dbg("ERROR: {$o->error}");
        return null;
    }
    return $o->value;
}
function cacheSet($k, $o, $ttl = 0)
{
    global $cacheHost;
    $v = obj2json($o);
    $r = cache($cacheHost, array('act' => 'set', 'key' => $k, 'val' => $v, 'ttl' => (int) $ttl));
    //echo "(cacheSet($k, $v) returning $r)\n";
    return $r;
}
function cacheGet($k)
{
    global $cacheHost;
    $v = cache($cacheHost, array('act' => 'get', 'key' => $k));
    //echo "(cacheGet($k) returning ".($v === null ? "null" : $v).")\n";
    return $v;
}
if (false) {
    // test code
    $cc = "(from cache)";
    $v = cacheGet("foo");
    if ($v == null) {
        $v = 15;
        $cc = "";
        cacheSet("foo", $v, 10);
    }
    echo "v is {$v} {$cc}\n";
}