asp定時(shí)生成靜態(tài)HTML的代碼
更新時(shí)間:2010年06月20日 23:45:29 作者:
asp定時(shí)生成靜態(tài)HTML的代碼,對(duì)于緩解服務(wù)器壓力有很大幫主,需要的朋友可以參考下。
復(fù)制代碼 代碼如下:
<%
'判斷是否要生成新的HTML
if Application("cache_asptohtml_date")="" then
Application.Lock
Application("cache_asptohtml_date")=now()
Application.Unlock
Call aspTohtml
Response.Redirect("index.html")
end if
if DateDiff("s", Application("cache_asptohtml_date"),Now)> 100 then '比較上次更新時(shí)間與當(dāng)前時(shí)間相差多少秒
Application.Lock
Application("cache_asptohtml_date")=now()
Application.UnLock
Call aspTohtml
Response.Redirect("index.html")
Else
Response.Redirect("index.html")
End if
'獲取當(dāng)前目錄!
function getpath
if Request.ServerVariables("SERVER_PORT")<>"80" then
UserUrl = "http://"&Request.ServerVariables("SERVER_NAME")& ":" & Request.ServerVariables("SERVER_PORT")& Request.ServerVariables("URL")
else
UserUrl = "http://"&Request.ServerVariables("SERVER_NAME")& Request.ServerVariables("URL")
end if
getpath=left(UserUrl,InstrRev(UserUrl,"/"))
end function
sub aspTohtml
'----------------------------------------------------------
'使用XMLHTTP生成靜態(tài)首頁(yè)的代碼
'Curl 為你的首頁(yè)地址,確保你的空間支持FSO
'-----------------------------------------------------------
dim read,Curl,content
Curl=getpath&"home.asp"
read=getHTTPPage(Curl)
if read<>"" then
content=read
Set Fso = Server.CreateObject("Scripting.FileSystemObject")
Filen=Server.MapPath("index.html")
Set Site_Config=FSO.CreateTextFile(Filen,true, False)
Site_Config.Write content
Site_Config.Close
Set Fso = Nothing
end if
End sub
Function getHTTPPage(url)
dim http
set http=Server.createobject("Microsoft.XMLHTTP")
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
set http=nothing
if err.number<>0 then err.Clear
End Function
Function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
%>
ASP定時(shí)生成靜態(tài)頁(yè)(HTML)2
復(fù)制代碼 代碼如下:
<%
set fs=server.createobject("scripting.filesystemobject")
file=server.mappath("time.txt")
set txt=fs.opentextfile(file,1,true)
if not txt.atendofstream then
times=txt.ReadLine
Else
response.write "<br /><!--有沒有發(fā)現(xiàn)time.txt 開始生成!-->"
HtmlPage = "time.txt" '//生成的HTML文件名
Template = NOW()
Set FSO = Server.CreateObject ("Scripting.FileSystemObject")
Set FileOut = FSO.CreateTextFile(Server.MapPath (HtmlPage))
FileOut.WriteLine Template
FileOut.Close
Set FSO = Nothing
end If
If datediff("s",times,NOW()) > 3600 Then '//上次更新到現(xiàn)在的時(shí)間 大于 3600秒 則 更新
response.write "<br /><!--時(shí)間過了開始更新-->"
code = "這里是需要生成的html代碼" '//如何得到代碼的方式有很多
'//用FSO生成HTML頁(yè)面
HtmlPage = "index.html" '//生成的HTML文件名
Template = code
Set FSO = Server.CreateObject ("Scripting.FileSystemObject")
Set FileOut = FSO.CreateTextFile(Server.MapPath (HtmlPage))
FileOut.WriteLine Template
FileOut.Close
Set FSO = Nothing
'//用FSO生成time.txt文件
HtmlPage = "time.txt" '//生成的HTML文件名
Template = NOW()
Set FSO = Server.CreateObject ("Scripting.FileSystemObject")
Set FileOut = FSO.CreateTextFile(Server.MapPath (HtmlPage))
FileOut.WriteLine Template
FileOut.Close
Set FSO = Nothing
Else
response.write "<br /><!-- 已經(jīng)過去"&datediff("s",times,NOW())&"秒!-->"
End If
%>
相關(guān)文章
利用AdoDb.Stream對(duì)象來(lái)讀取UTF-8格式的文本文件
利用AdoDb.Stream對(duì)象來(lái)讀取UTF-8格式的文本文件...2006-10-10ASP UTF-8編碼下字符串截取和獲取長(zhǎng)度函數(shù)
截取文字長(zhǎng)度函數(shù),支持UTF-8 ,這樣就可以滿意大部分截取字符串的朋友了。2009-05-05轉(zhuǎn)換中文為unicode 轉(zhuǎn)換unicode到正常文本
轉(zhuǎn)換中文為unicode 轉(zhuǎn)換unicode到正常文本...2006-10-10asp 實(shí)現(xiàn)顯示所有的服務(wù)器變量值的函數(shù)
asp 實(shí)現(xiàn)顯示所有的服務(wù)器變量值的函數(shù)...2007-08-08ASP生成數(shù)字相加求和的BMP圖片驗(yàn)證碼
以前我自己寫了個(gè)是文字的,但還是這個(gè)好,都是圖片的2008-08-08ASP MSSQL存儲(chǔ)過程的實(shí)現(xiàn)小例
很多朋友學(xué)ASP以后,就只會(huì)簡(jiǎn)單的SELECT、UPDATE、DELETE幾個(gè)基本命令。這樣在讀取或者存入數(shù)據(jù)的時(shí)候,大大降低的系統(tǒng)運(yùn)行的速度。2009-02-02