hello everyone !!
I'm trying to make a game of answers and questions, using php and OkHttpUtils2, but I have a problem with the requests ( Job.Download and Job.PostString )
B4X code :
B4X:
'Static code module
Sub Process_Globals
Private fx As JFX
Private GameTimer As Timer
End Sub
Sub EnterGame
GameTimer.Initialize("GameTimer", 500)
GameTimer.Enabled = True
End Sub
Sub GameTimer_Tick
Dim j As HttpJob
j.Initialize("", Me)
'j.Download("http://localhost/getviews.php")
j.PostString("http://localhost/getviews.php","")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Log(j.GetString)
End If
j.Release
End Sub
Best guess, on top of my mind, is that the server is somewhat slow and doesn't finish the request fast enough (until the server "warms up" and manages to keep pace). So your B4X code sends the request several times before the server part gets to increase the variable.
This theory should be very simple to test by increasing the gametimer to a higher value. I would test with 1000 or perhaps even 5000, to see if the theory holds water.
try lengthening the delay on the timer. also, read very carefully the documentation relating to $_SESSION for your particular version of php. for example, the $_SESSION variable can be reset (unbeknownst to you). there are other considerations, which may or may not be relevant here. start with your timer and see if there's a difference. you can always tweak it to your liking.
'You'll need to set up a global variable for this
'Public getviewsBusy As Boolen = False
Sub GameTimer_Tick
If getviewsBusy then return
getviewsBusy = True
Dim j As HttpJob
j.Initialize("", Me)
Try
'j.Download("http://localhost/getviews.php")
j.PostString("http://localhost/getviews.php","")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Log(j.GetString)
End If
Catch
Log(LastException)
End Try
j.Release
getviewsBusy = False
End Sub