PHP浏览次数统计类visit.class.php配合文本缓存
使用示例:
$visit = app::loader('visit');
$article_id = 20722;
$visit->count('article', $article);
<?php class visit { public $expires = array(); public $tables = array(); public function __construct() { $this->expires['article'] = 10; $this->tables['article'] = 'pcb_article'; $this->expires['forum'] = 9; $this->tables['forum'] = 'pcb_forum'; $this->expires['blog'] = 8; $this->tables['blog'] = 'pcb_blog'; } public function count($channel, $id) { $path = $this->get_cache_path($channel); $this->update($path, $channel, $id); } private function get_cache_expires($channel) { $expires = isset($this->expires[$channel]) ? $this->expires[$channel] : 10; return $expires; } private function get_cache_path($channel) { $time = time(); $minute = date('H', $time) * 60 + date('i', $time); $expires = $this->get_cache_expires($channel); $path = SYS_PATH ."/data/cache/visit/{$channel}". ceil($minute / $expires) .".txt"; return $path; } private function update($path, $channel, $id) { $dir = dirname($path); if (!file_exists($dir)) make_dir($dir); if (file_exists($path)) { file_put_contents($path, ',' . $id, FILE_APPEND|LOCK_EX); } else { $table = $this->tables[$channel]; $mysql = app::loader('mysql'); $hand = opendir($dir); while (($file = readdir($hand))) { if (preg_match("/{$channel}/", $file)) { $visit = file_get_contents("{$dir}/{$file}"); $array = explode(',', $visit); $array = array_count_values($array); unset($array['']); $sql = ''; foreach ($array as $id => $visit) { $sql .="UPDATE `{$table}` SET `visit` = `visit` + {$visit} WHERE `id` = {$id} LIMIT 1;"; } if ($sql) { $res = $mysql->executes($sql); if ($res) unlink($dir . '/' . $file); } unset($sql); } } file_put_contents($path, ',' . $id, LOCK_EX); } } }
登入後複製
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
刺客信條陰影:貝殼謎語解決方案
2 週前
By DDD
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
3 週前
By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)
