2012-12-01 44 views
0

我想知道用什麼函數來緩存所拉取的數據並在15-30分鐘後才刷新它。用於從mysql表中提取數據的php腳本的緩存選項

這裏是從mysql數據到網站的PHP腳本。

<?php 
include('mysql_connection.php'); 

$c = mysqlConnect(); 

$locale = $_GET['locale']; 
$last_bulletins_id = $_GET['bulletins_id']; 

sendQuery ("set character_set_results='utf8'"); 
sendQuery ("set collation_connection='utf8_general_ci'"); 

if(strcmp($locale,"en") != 0) 
$locale = "en"; 
$result = sendQuery(" 
SELECT bulletins.id, posted_date, message, name 
FROM bulletins 
LEFT JOIN players ON (bulletins.player_id = players.user_id) 
WHERE bulletins.id > ".$last_bulletins_id." and locale = '".$locale."' 
ORDER BY bulletins.id DESC 
LIMIT 10"); 
echo '<table width=\"100%\">'; 
while($row = mysql_fetch_array($result, MYSQL_NUM)) 
{ 
    echo '<tr><td width=\"100%\"><b>Date: </b>'.$row[1].'</td></tr>'; 
    echo '<tr><td width=\"100%\"><b>Author: </b>'.$row[3].'</td></tr>'; 
    echo '<tr><td width=\"100%\">'.nl2br($row[2]).'</td></tr>'; 
    echo '<tr><td width=\"100%\"><hr style="height: 2px; border: none; background: #515151;"></td></tr>'; 
} 
echo '</table>';  

mysqlClose($c); 

?>

回答

0

你應該寫數據,你在緩存文件輸出和檢查多少時間已經從文件加載緩存文件的最後修改通過或查詢數據庫,並輸出新的結果,如果時間大於您設定的限制。這些功能會方便你:

file-put-contents

filemtime

touch

file-exists

相關問題