欢迎光临
我们一直在努力

以前收集的一些资料—(一种新思路)使用一个“静态”的ASP页面来改进你的服务器的性能

建站超值云服务器,限时71元/月

使用一个“静态”的asp页面来改进你的服务器的性能
通常大家显示一个数据库中的信息时都是使用动态页面来生成的,
这对于一个小网站或者当数据库内的容量不大时,系统的性能并没有什么影响。
但是当用户要频繁地访问一个数据量很大的库时,系统是不是还能够承受得了了。
下面介绍一种“静态”asp技术来解决这个问题。
例如现在这个有一个人员资料库,结构如下:
id    first     last         company      email       phone
常规的办法如下:
contact.asp
                           <table cellspacing=0 cellpadding=0>
                           <%
                              set query = getdb.execute("select * from contacts order by firstname, lastname")
                              do while not query.eof

                                 response.write "<tr><td><a href="""
                                 response.write "detail.asp?id=" & query("id")
                                 response.write """>" & query("first") & " " & query("last")
                                 response.write "</a></td></tr>"         
                                 query.movenext

                              loop
                              query.close
                              set query = nothing
                           %>
                           </table>

detail.asp
                           <table cellspacing=0 cellpadding=0>
                           <%
                              set query = getdb.e xecute("select * from contacts where id=" & request("id"))
                              if not query.eof then

                                 response.write "<tr>"
                                 response.write "<td>name: </td><td>" & query("first") & " " & query("last") & "</td>"
                                 response.write "<td>company: </td><td>" & query("company") & "</td>"
                                 response.write "<td>e-mail: </td><td>" & query("email") & "</td>"
                                 response.write "<td>phone: </td><td>" & query("phone") & "</td>"
                                 response.write "</tr>"

                                 query.movenext

                              end if
                              query.close
                              set query = nothing
                           %>
                           </table>

我想大家对上面的代码应该是不会有什么疑问的,显然它存在我上面提出的那个问题。
就是当每次显示一个人的详细资料时,都会读取数据库。
现在我提出的这个想法其实很简单,就是使用一个“静态”的asp页面来代替读取数据库
的操作。
调用格式如下:
"contact" & id & ".asp"
例如我想读取id为27的人的信息,我就不用去查取数据库了,只要显示一个静态的
"contact27.asp"就可以了。
这时你也许会说,如果我要改变了一个人的信息怎么办,其实只要在将
用户信息保存后的同时也改写这个静态页面,代码如下,有没有兴趣研究研究呀。
                           sub generatecontactcachefile(id)
                              dim query
                              set query = getdb.execute("select * from contacts where id=" & id)
                              if not query.eof then
                                  dim filename
                                 filename = "contact" & id & ".asp"
                                 dim fso
                                 set fso = server.createobject("scripting.filesystemobject")
                                 dim file
                                 set file = fso.createtextfile(filename)
                                 file.writeline "<html><head>"
                                 file.writeline "<title>contact: " & query("first") & " " & query("last") & "</title>"
                                 file.writeline "</head><body>"
                                 file.writeline "<table cellspacing=0 cellpadding=0>"
                                 file.writeline "<tr>"
                                 file.writeline "<td>name: </td><td>" & query("first") & " " & query("last") & "</td>"
                                 file.writeline "<td>company: </td><td>" & query("company") & "</td>"
                                 file.writeline "<td>e-mail: </td><td>" & query("email") & "</td>"
                                 file.writeline "<td>phone: </td><td>" & query("phone") & "</td>"
                                  file.writeline "</tr>"
                                 file.writeline "</table>"
                                 file.writeline "</body></html>"
                                 file.close
                                 set file = nothing   
                              end if
                              query.close
                              set query = nothing

                           end sub
使用模版,很多人在编程的时候都喜欢使用模版文件,我也很喜欢这样
因为这样能够让整个网站的风格保持一致,同时还可以免去讨厌的frame
一个典型的使用模版文件的代码如下:
                           <html>
                              <head>
                                 <title>我的主页</title>
                                 <!– #include file="style.inc" –>
                              </head>
                              <body>
                                 <!– #include file="navstart.inc" –>
                                 <!– #include file="adbox.inc" –>

                ……这一页的内容…..

                                 <!– #include file="adbox.inc" –>
                                 <!– #include file="navend.inc" –>
                              </body>      
                           </html>

这样,当你有多个“静态”页面时,尤其是上万个页面时,可以使用下面这种方式:
                           sub generateheader(file, title)
                              file.writeline "<html><head>"
                              file.writeline "<title>" & title & "</title>"
                              file.writeline "<!– #include file="style.inc" –>"
                              file.writeline "</head></body><body>"
                              file.writeline "<!– #include file="navstart.inc" –>"
                              file.writeline "<!– #include file="adbox.inc" –>"
                           end sub

                           sub generatefooter(file)
                              file.writeline "<!– #include file="adbox.inc" –>"
                              file.writeline "<!– #include file="navend.inc" –>"
                              file.writeline "</body></html>"
                           end sub   

                           generateheader file, "contact: " & query("first") & " " & query("last")
                           file.writeline "<table cellspacing=0 cellpadding=0>"
                           file.writeline "<tr>"
                           file.writeline "<td>name: </td><td>" & query("first") & " " & query("last") & "</td>"
                           file.writeline "<td>company: </td><td>" & query("company") & "</td>"
                           file.writeline "<td>e-mail: </td><td>" & query("email") & "</td>"
                           file.writeline "<td>phone: </td><td>" & query("phone") & "</td>"
                           file.writeline "</tr>"
                           file.writeline "</table>"
                           generatefooter file

最后是在contacts.asp中把从数据库中读数据改成读“静态页面”就可以了。
                           response.write "<tr><td><a href="""
                           response.write "contact" & query("id") & ".asp"    point the link to the cache page…
                           response.write """>" & query("first") & " " & query("last")
                           response.write "</a></td></tr>"          
试试把,这个方法能够把你服务器的性能大大提高的哦。

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 以前收集的一些资料—(一种新思路)使用一个“静态”的ASP页面来改进你的服务器的性能
分享到: 更多 (0)

相关推荐

  • 暂无文章