Das mit den POST und GET-Daten muss ich jetzt nur noch herausfummeln. Das sollte aber kein Thema sein. Bleibt aber noch die Frage nach dem Multithreading. Und tatsächlich ist auch das kein Problem. Man kann mehrere Threads erstellen und alle können die gleiche Art von Schleife abarbeiten. Und dadurch, das die Prozeduren ja private sind, sollte es auch da keine Probleme mit dem ganzen geben. Einzig für z.B. globale Datenbankverbindung müsste man etwas tricksen, da man die durchaus auch global definieren kann. Aber vom einfachen Grundsatz her kann man es so machen:
Code: Alles auswählen
OpenConsole()
Procedure WriteCGIConstant(Constant$)
WriteCGIString(Constant$ + ": " + CGIVariable(Constant$)+"<br>")
EndProcedure
If Not InitCGI()
End
EndIf
If Not InitFastCGI(5600) ; Create the FastCGI program on port 5600
End
EndIf
Procedure goon()
While WaitFastCGIRequest()
PrintN("Incomming Request!")
If ReadCGI()
WriteCGIHeader(#PB_CGI_HeaderContentType, "text/html", #PB_CGI_LastHeader) ; Write the headers to inform the browser of the content format
WriteCGIString("<html><title>PureBasic CGI</title><body>")
WriteCGIConstant(#PB_CGI_AuthType)
WriteCGIConstant(#PB_CGI_ContentLength)
WriteCGIConstant(#PB_CGI_HeaderContentType)
WriteCGIConstant(#PB_CGI_DocumentRoot)
WriteCGIConstant(#PB_CGI_GatewayInterface)
WriteCGIConstant(#PB_CGI_PathInfo)
WriteCGIConstant(#PB_CGI_PathTranslated)
WriteCGIConstant(#PB_CGI_QueryString)
WriteCGIConstant(#PB_CGI_RemoteAddr)
WriteCGIConstant(#PB_CGI_RemoteHost)
WriteCGIConstant(#PB_CGI_RemoteIdent)
WriteCGIConstant(#PB_CGI_RemotePort)
WriteCGIConstant(#PB_CGI_RemoteUser)
WriteCGIConstant(#PB_CGI_RequestURI)
WriteCGIConstant(#PB_CGI_RequestMethod)
WriteCGIConstant(#PB_CGI_ScriptName)
WriteCGIConstant(#PB_CGI_ScriptFilename)
WriteCGIConstant(#PB_CGI_ServerAdmin)
WriteCGIConstant(#PB_CGI_ServerName)
WriteCGIConstant(#PB_CGI_ServerPort)
WriteCGIConstant(#PB_CGI_ServerProtocol)
WriteCGIConstant(#PB_CGI_ServerSignature)
WriteCGIConstant(#PB_CGI_ServerSoftware)
WriteCGIConstant(#PB_CGI_HttpAccept)
WriteCGIConstant(#PB_CGI_HttpAcceptEncoding)
WriteCGIConstant(#PB_CGI_HttpAcceptLanguage)
WriteCGIConstant(#PB_CGI_HttpCookie)
WriteCGIConstant(#PB_CGI_HttpForwarded)
WriteCGIConstant(#PB_CGI_HttpHost)
WriteCGIConstant(#PB_CGI_HttpPragma)
WriteCGIConstant(#PB_CGI_HttpReferer)
WriteCGIConstant(#PB_CGI_HttpUserAgent)
WriteCGIString("</body></html>")
EndIf
FinishFastCGIRequest()
PrintN("Request Finished!")
Wend
EndProcedure
th1 = CreateThread(@goon(),0)
th2 = CreateThread(@goon(),0)
th3 = CreateThread(@goon(),0)
th4 = CreateThread(@goon(),0)
WaitThread(th4)
Eine weitere Möglichkeit wäre es auch, das ganze einfach den Webserver machen zu lassen. Und zwar durch den Loadbalancer. Man kann den Server ja mit unterschiedlichen Netzwerkports laufen lassen und die dem Webserver als target für das Loadbalancing angeben. Der Webserver verteilt dann die Request auf die einzelnen Instanzen.