2011年7月7日

由client端判斷時間,捉取更新網頁

當使用者端連進來時,
由 index.php 負責判斷時間,
當上一個連線與這一個連線時間小於 600 秒,
就讀取 index2.htm ,
如果上一個連線與這一個連線時間已超過 600 秒,
就會乎叫 get.php ,
重新將 RSS 的網頁讀取進來,
並寫到 index2.htm 裡面去,
供下一次 600 秒內的使用者閱讀。

目的:避免在短時間有大量的 PHP 處理程序將資源吃光。

index.php
<?php
$t=time();
$fp = fopen('timestamp.txt', 'r');
$datatime=fgets($fp,12);
$t2=$t-$datatime;

if ($t2<600){include("index2.htm");
} else {
include("get.php");
}
?>

get.php
<?php
$siteurl = "http://samba.tw/rss.php";
$content = file_get_contents($siteurl);
echo $content;

$fp2 = fopen('index2.htm', 'w');
fwrite($fp2,$content);
fclose($fp2);

$t=time();
$fp = fopen('timestamp.txt', 'w');
fwrite($fp,$t);
fclose($fp);
?>

index2.htm (空白檔案即可,注意要有寫入的權限)

timestamp.txt(空白檔案即可,注意要有寫入的權限)

2011年7月1日

網頁版批踢踢 (web ptt.cc)

如果無法用 telnet 連進 ptt.cc 進行 BBS 的操作~
可以選用網頁方式進行瀏覽
http://www.ptt.cc/bbs/index.html
雖然沒有 BBS 那麼多功能,
但是簡易的閱讀也可以止一下渴啦!