国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

用ASP開"多線程"

2024-05-04 10:59:10
字體:
來源:轉載
供稿:網友

在網上找到一個用ASP開的假線程,發現和我以前做的一個程序不謀而合,只不過以前用的是VB,摘下來,儲備.

1.原理實驗 原理當然都一樣,利用web服務器支持多線程,在同一頁面里向服務器發多個http請求來完成我們的工作。還是先實驗一下,在一個頁面里同時寫2個txt文件,比較寫入時間的差異。代碼如下: <%

startime=timer()
''----------asp實現多線程----------''
function runThread()
dim Http
set Http=Server.createobject("Msxml2.XMLHTTP")
Http.open "GET","http://127.0.0.1/thread.asp?action=b",false
Http.send()
end function
function a()
dim Content,FilePath,MyFile
Content=now()&chr(30)&timer()
FilePath=server.MapPath("a.txt")
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile(FilePath, True)
MyFile.Write(Content)
MyFile.Close
end function
function b()
dim Content,FilePath,MyFile
Content=now()&chr(30)&timer()
FilePath=server.MapPath("b.txt")
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile(FilePath, True)
MyFile.Write(Content)
MyFile.Close
end function
if(Request.QueryString("action")="") then
runThread()
a()
else
b()
end if
%> Script Execution Time:<%=fix((timer()-startime)*1000)%>ms 運行后的結果顯示: a文件和b文件中的時間是基本相同的。 2.實際應用比較 比如我同時抓取2個頁面的html代碼,一個sohu首頁,一個是sina首頁,用2種方式:一個是常規的順序的代碼執行,單線程執行,一個是這里的多線程執行,比較頁面完成時間,代碼如下: testspeed1.asp: <%
startime=timer()
function getHTTPPage(url)
on error resume next
dim http
set http=Server.createobject("Msxml2.XMLHTTP")
Http.open "POST",url,false
Http.send()
if Http.readystate<>4 then exit function
getHTTPPage=bytes2BSTR(Http.responseBody)
contents = getHTTPPage
Response.Write "<xmp>"
Response.Write(contents)
Response.Write "</xmp>"
set http=nothing
if err.number<>0 then err.Clear
end function
Function bytes2BSTR(vIn)
dim strReturn
dim i,ThisCharCode,NextCharCode
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
getHTTPPage("http://www.sohu.com/")
getHTTPPage("http://www.sina.com.cn/")
%> Script Execution Time:<%=fix((timer()-startime)*1000)%>ms Testspeed2.asp: <%
startime=timer()
function getHTTPPage(url)
on error resume next
dim http
set http=Server.createobject("Msxml2.XMLHTTP")
Http.open "POST",url,false
Http.send()
if Http.readystate<>4 then exit function

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 五常市| 长兴县| 正安县| 龙口市| 台江县| 通河县| 金湖县| 奉贤区| 平谷区| 永善县| 从江县| 安义县| 元氏县| 高安市| 静乐县| 龙门县| 星子县| 醴陵市| 东港市| 长沙市| 兴义市| 手机| 泾源县| 左权县| 台南县| 南郑县| 柞水县| 东山县| 肥城市| 平阴县| 温宿县| 四会市| 伊金霍洛旗| 宿迁市| 偏关县| 呼伦贝尔市| 美姑县| 宁河县| 重庆市| 陕西省| 搜索|