I use a server-side PHP file to connect to MySQL Database. the code is like this:
Everything is Ok except that the session remains open, and when this routine is executed more and more, a large number of open sessions violate the host service regulations.
How can I close the open session?
Another solution is to reuse the open session instead of closing it.
Does anyone have any idea of each of these?
B4X:
Sub Class_Globals
Pivate Root As B4XView
Private xui As XUI
Private webClient As OkHttpClient
Private webStream As OutputStream
Private lastResponse As OkHttpResponse
...
End Sub
Private Sub LoadDataFromMySQLDatabase()
Dim tRequest As OkHttpRequest
tRequest = NDatabase.CreatePostRequest(<Url of the PHP File>,<parameters>)
webClient.Execute(tRequest, 1)
End Sub
Private Sub webClient_ResponseError (Response As OkHttpResponse, Reason As String, _
StatusCode As Int, TaskId As Int)
Log("Web error: " & Response.ErrorResponse & " (" & StatusCode & ") " & Reason)
Response.Release
End Sub
Private Sub webClient_ResponseSuccess (Response As OkHttpResponse, TaskId As Int)
webStream.InitializeToBytesArray(0)
Response.GetAsynchronously("webResponse", webStream, True, TaskId)
lastResponse=Response
End Sub
Private Sub webResponse_StreamFinish (Success As Boolean, TaskId As Int)
Dim arrOutput () As Byte
arrOutput = webStream.ToBytesArray
Dim txtOutput As String=BytesToString(arrOutput, 0, arrOutput.Length, "UTF8")
Log (txtOutput)
Select TaskId
Case 1
... (using loaded data)
...
End Select
lastResponse.Release
End Sub
How can I close the open session?
Another solution is to reuse the open session instead of closing it.
Does anyone have any idea of each of these?