function updateMemcache() { // ignore_user_abort(); //set_time_limit(0); //$interval=3600; //(seconds) require_once 'model/Feed.php'; require_once 'lib/BitMemCache.php'; require_once 'lib/RssReader.php'; $feed = new Feed(); $feeds = $feed->getFeeds(); $logger = LogUtil::getLogger(); //do{ include "config/site.php"; foreach ($feeds as $feed) { $url = $feed['url']; $mem = new BitMemCache(); $reader = new RssReader(); $rss = $reader->fetch($url); if (!$rss) { } else { if ($mem->init()) { $mem->set($url, json_encode($rss)); $logger->info("update memcache {$url}"); } } } // sleep($interval); //}while($memcache); }
function __construct() { include "config/config.php"; //no include_once, because only first new XXX() will include config.php $this->db = new MySQL($mysql_host, $mysql_user, $mysql_pass, $mysql_dbname); $this->logger = LogUtil::getLogger(); }
function fetch($url) { $cacheDir = "cache/"; $cacheName = base64_encode($url); $fullUrl = $cacheDir . $cacheName; $hasCache = is_file($fullUrl); require_once "lib/LogUtil.php"; $logger = LogUtil::getLogger(); if ($hasCache) { // 有缓存且缓存的时间不超过6小时则使用缓存 $t1 = filemtime($fullUrl); $t2 = time(); $inter = $t2 - $t1; if ($inter < 3600 * 6) { $url = $fullUrl; $logger->info("fullUrl = {$fullUrl} inter={$inter} t1={$t1}"); } else { $hasCache = false; $logger->info("inter={$inter}"); } } $logger->info("url={$url}"); $buff = ""; $timeout = array('http' => array('timeout' => 20)); $ctx = stream_context_create($timeout); $fp = fopen($url, "r", false, $ctx); if (!$fp) { return false; } while (!feof($fp)) { $buff .= fgets($fp, 4096); } fclose($fp); if (strlen($buff) <= 0) { return false; } //$pattern="/<!\[CDATA\[(.*?)\]\]>/"; //preg_match_all($pattern, $str,$out); //var_dump($out); $from_str = "encoding=\"gb2312\""; $to_str = "encoding=\"UTF-8\""; $char_set = mb_detect_encoding($buff); if ($char_set == 'UTF-8') { } else { // $buff = mb_convert_encoding($buff,'utf-8','gb2312'); --不支持生僻字,需改成GBK $buff = mb_convert_encoding($buff, 'utf-8', 'GBK'); $buff = str_replace($from_str, $to_str, $buff); } if (!$hasCache) { $cacheFp = fopen($fullUrl, 'w+'); fwrite($cacheFp, $buff); fclose($cacheFp); $t3 = filemtime($fullUrl); $logger->info("fullUrl={$fullUrl} t3={$t3}"); } return simplexml_load_string($buff, 'SimpleXMLElement', LIBXML_NOCDATA); }
function __construct($path, $usr, $pass_wd, $db_name) { if ($this->conn == null) { $this->conn = mysql_connect($path, $usr, $pass_wd, true) or die("cannot connect datebase " . $path . " :" . mysql_error()); mysql_select_db($db_name, $this->conn) or die("cannot select datebase " . $db_name . " :" . mysql_error()); mysql_query("SET NAMES UTF8"); } $this->logger = LogUtil::getLogger(); }
public function saveTpl() { $arr = array('tpl_name', 'tpl_root'); $_POST['tpl_root'] = "view/template/" . $_POST['tpl_name']; require_once "lib/LogUtil.php"; $logger = LogUtil::getLogger(); //$logger->info($_POST['tpl_name']); //$logger->info($_POST['tpl_root']); return $this->db->postInsertPair("siteparas", $arr); }
function listPage() { $postTile = ""; $postBlockName = ""; $sts = "1"; if (isset($_POST['title'])) { $postTile = $_POST["title"]; } if (isset($_POST['sts'])) { $sts = $_POST["sts"]; } if (isset($_POST['block_name'])) { $postBlockName = $_POST["block_name"]; } $table = "(select a.*,b.block_name,c.usr_nm from content a left join block b on a.block_id=b.block_id left join users c on a.usr_id=c.usr_id where a.sts in (" . formatString($sts) . ") and a.title like '%" . $postTile . "%' and b.block_name like '%" . $postBlockName . "%' order by edit_tm desc) mytable"; $this->logger = LogUtil::getLogger(); //$this->logger->info($table); $pager = parent::getPager($table, $this->content->db); $arrayList = $pager->getData(); $blockList = $this->block->getBlocks(); require 'view/admin/content_list.php'; }
function flushMem() { $mem = new BitMemCache(); if ($mem->init()) { $logger->info("init 2"); $logger = LogUtil::getLogger(); $ret = $mem->flush(); $logger->info("flush memcache ------------[ {$ret} ]"); } echo "flushMem 2"; }
function __construct() { parent::__construct(); $this->logger = LogUtil::getLogger(); }