function do_history($chars, $max = 20) { require_once 'lib/php-file-cache/fcache.inc.php'; $fcache = new FCache(); $history = $fcache->get('hash_history'); if (!$history) { $history = array(); } if (array_key_exists($chars, $history)) { return array_keys($history); } if (count($history) > $max) { $key_del = array_rand($history, 1); unset($history[$key_del]); } $history[$chars] = ''; $fcache->add('hash_history', $history); return array_keys($history); }
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器 // 3. 执行并获取 HTML 文档内容 $output = curl_exec($ch); if ($output === FALSE) { echo "cURL Error: " . curl_error($ch); } $sug1 = json_decode($output); // 4. 释放 curl 句柄 curl_close($ch); $sug = @$sug1[1][0]; if (strlen($sug) > 0) { echo $sug . '_'; $cache->add(urlencode($query), $sug); } } // 引号转换为 HTML 实体的查询词作为副标题 echo htmlspecialchars($z, ENT_QUOTES) . '_'; } // 标题后缀,品牌名 echo $pt . '</title> '; // 下拉框提示词第 1 位,查询词作为 meta keywords echo '<meta content="'; if (strlen($s) > 0) { if (strlen($cache->get(urlencode($query))) > 0) { echo $cache->get(urlencode($query)) . ','; } elseif (strlen($sug) > 0) { echo $sug . ',';
<?php require_once 'fcache.inc.php'; //example $cache = new FCache(); $storeData = array('time' => time(), 'str' => 'test', 'int' => 1321); $cache->add('select * from table;', $storeData); $cache->add('select * from table;', $storeData); $cache->add('select * from table;', $storeData); $cache->add('select * from table;', $storeData); print_r($storeData = $cache->get('select * from table;')); $cache->delete('select * from table;'); print_r($cache->get('select * from table;') ? 'exist' : 'has no cache'); $cache->add('select * from table1;', 123); $cache->add('select * from table2;', 234); $cache->add('select * from table3;', 345); $cache->flush(); print_r($cache->get('select * from table3;') ? 'exist' : 'has no cache');