使用示例:
$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); } } }
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Assassin's Creed Shadows: Seashell Riddle Solution
2 weeks agoByDDD
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Linux new version
SublimeText3 Linux latest version