【发布时间】:2017-06-02 13:12:21
【问题描述】:
我需要控制谁以及何时进入每个子页面,并将这些信息插入 MySQL。我有 MYSQL 表,它将获取信息(用户 ID、子页面、子页面 ID、日期时间)。
function logstore(){
global $DB, $USER, $CFG;
$protocol = strpos(strtolower($_SERVER['SERVER_PROTOCOL']),'https')
=== FALSE ? 'http' : 'https';
$host = $_SERVER['HTTP_HOST'];
$script = $_SERVER['SCRIPT_NAME'];
$currentUrl = $protocol . '://' . $host . $script;
$newsurl = $CFG->wwwroot.'/news/view.php';
$produrl = $CFG->wwwroot.'/prod/view.php';
$materialurl = $CFG->wwwroot.'/material/index.php';
$datetime = date_create()->format('Y-m-d H:i:s');
$records = new stdClass();
$records->userid = $USER->id;
if($currentUrl == $newsurl){
$records->activity = 'news';
$records->activityid = $_GET['id'];
}elseif ($currentUrl == $produrl){
$records->activity = 'prod';
$records->activityid = $_GET['id'];
}
elseif ($currentUrl == $materialurl){
$records->activity = 'material';
$records->activityid = $_GET['id'];
}
$records->datetime = $datetime;
$DB->insert_record('logstore', $records);}
我在 /news/view.php、/prod/view.php、/material/index.php 之上调用此函数。
它工作正常,但我需要对其进行一些优化。有什么方法可以在数据库空闲时插入这些记录,或者创建列表并每小时插入一次?
//编辑
我尝试了 INSERT DELAYED 但它不适用于我的数据库:(
【问题讨论】: