User: ori Date: 12-8-10 Time: 下午9:48 To change this template use File | Settings | File Templates.
Exemple #1
0
$cfg = new config();
$db = new dbQuery($cfg->dbHost, $cfg->dbUser, $cfg->dbPassword, $cfg->dbName);
$indexCache = new indexContent();
$viewID = InStr('view-', '.html', $_SERVER["REQUEST_URI"]);
//当前百度问答采集页面ID。范围从1-10。对应baidu1-baidu10
//--------------------从数据库中读取-------------------------------------
$sqlSelect = 'SELECT `cid`,`title`,`key`,`keys`,`adkey`,`index`,`baidu' . $viewID . '` FROM `' . $indexCache->dbPrefix . "cat` WHERE `epath`='" . $indexCache->epath . "';";
$result = $db->query($sqlSelect);
$arrResult = $db->fetch_array($result);
//--------------------初始化数据--------------------------------------------
$indexCache->AnalysisData($arrResult, (array) $viewID);
//将viewid转换成数组
$indexCache->AnalysisCache();
$arrResult = null;
unset($arrResult);
$baidu = new baidu();
$baidu->AnalysisCache($indexCache->conBaidu[$viewID]);
$baidu->SetKey($indexCache->key);
$baidu->SetViewId($viewID);
$baidu->CrawlView();
//--------------------更新数据库--------------------------------------------
if ($baidu->isUp) {
    $sqlUpdate = 'UPDATE `' . $indexCache->dbPrefix . 'cat` SET `baidu' . $viewID . '`=\'' . addslashes($baidu->GetSerializeCache()) . '\' WHERE `cid`=' . $indexCache->cid;
    $db->query($sqlUpdate);
}
$db->close();
//--------------------输出--------------------------------------------
if ($cfg->isMemcached) {
    $memcached = new Memcached();
    $memcached->addServer('127.0.0.1', '11211');
}
$indexContent->SetCreateTime($createTime);
$indexContent->AnalysisCache();
//--------------------无需更新--------------------------------------------
if (!$indexContent->NeedUp() && $indexContent->conIndex != '') {
    $db->close();
    $indexContent->Show($cfg->isMemcached, $memcached);
    die;
}
$upTimes = $indexContent->cid > 500 ? 86400 : 432000;
$indexContent->SetUpTimes($upTimes);
//--------------------更新百度--------------------------------------------
$sqlUpBaidu = '';
$indexContent->CleanBaiduArray();
$baiduLinks = '';
foreach ($arrBaiduViewId as $k => $v) {
    $baidu = new baidu();
    $baidu->AnalysisCache($indexContent->conBaidu[$v]);
    $baidu->SetKey($indexContent->key);
    $baidu->SetViewId($v);
    $baidu->InsertLinks($baiduLinks);
    $baidu->CrawlList();
    $baiduLinks = $baidu->links;
    $indexContent->SetBaidu($v, $baidu->title, $baidu->description);
    if ($baidu->isUp) {
        $sqlUpBaidu .= ',`baidu' . $v . "`='" . addslashes($baidu->GetSerializeCache()) . "' ";
    }
    $baidu = NULL;
    unset($baidu);
}
//--------------------更新随机文章-----------------------------------------
$dayAfterCreate = (int) ((time() - $indexContent->createTime) / 86400);