Ooops
May 25, 2020, 12:39:37 PM

Author Topic: [ PHP ] An abstract question concerning the capabilities of PHP  (Read 1599 times)

Offline cpsmith0191

  • Jr. Member
  • **
  • Posts: 68
    • caroleandcarl
Firstly I am very new to PHP. I am tweaking some PHP script to imitate the much lamented (by me) GNet Lobby initially on my ‘apache server’ (thanks to all for your examples of PHP script).

This system seems to me to create a record in a data base that contains the IP and port of the game session creator. This is then maintained by the session creator until such time as a client (second player) joins the session then the record is allowed to ‘time out’ and is scrubbed by the php script. The local software then initiates all the TCIP port binding stuff and the players have to sort out any firewall, router problems via port forwarding etc. This is OK but I was thinking (a dangerous pastime) that for two player turn based games, IE games where speed of data transfer is not an issue the following model might be more appropriate.

Each copy of the software comes with the appropriate permissions to access the sql data base on my site for this game. Both players can read all cells in a record. Player 1 creates a session, PHP creates a record, info and say 8 cells and gets write access to 4 cells
Player 1  Cell 0 set to 1 = (I am connected)       Player 2   Cell 5 (set to 1 when player 2 connects) = (I am connected)
Player 1  Cell1 =  any sent data                        Player 2   Cell 6 = any sent data
Player 1  Cell2 = I have received data               Player 2   Cell 7 = I have received data
Player 1  Cell3 = I have sent data                     Player 2   Cell 8 = I have sent data
Player 2 when joining a session gets write access to cells 5 to 8 and sets cell5 = 1
A game turn would take the following form (player1’s data send)
Player 1 sets cell2=0, player 1puts data into cell1, player 1 sets cell3 to 1, player 1 monitors Cell7
Player 2 monitors Cell 3 until it reads 1, Player 2 reads the data in cell 1, Player 2 sets cell7=1
Player 1 reads cell7 =1 and sets cell3=0
Player2 then sends data by, Cell 7 =0, put data into cell 6, set cell 8 to 1, then monitors cell 2     (IE handshaking)
The loop would also include a timed check on cell 0 (cell 5) to check for disconnection/program termination.

This approach depends on the data in a record cell being dynamic, ie the data can be changed inside the record as time progresses.
Has this approach been tried by anybody? is it beyond the capabilities of PHP?
I’m asking as I don’t want to reinvent the wheel or chase phantoms with my rudimentary understanding of PHP. Have fun cps

Offline cpsmith0191

  • Jr. Member
  • **
  • Posts: 68
    • caroleandcarl
Re: An abstract question concerning the capabilities of PHP
« Reply #1 on: August 23, 2017, 04:19:44 PM »
Replying to myself (not a good sign). For PHP beginners viewing this, both systems described seem achievable using arrays without having to get involved with sql.
Permissions may be an issue and the fact my php script will be running continually may cause problems when put on a web site.
But this does simplify the experiment. Forward to 'get' and 'push' (blitz max style), Have fun cps

Offline Matty

  • Hero Member
  • *****
  • Posts: 1028
    • MattiesGames
Re: An abstract question concerning the capabilities of PHP
« Reply #2 on: August 24, 2017, 05:02:22 AM »
Hi cpssmith0191

I wrote a similar process for a different purpose with my space game in 2015.

You cannot have a php script run indefinitely...it doesn't make sense to do this...a php script is simply called every time a page is called and if it runs too long it will take up resources on the server and eventually time out.

You will have to store state of the object /array somewhere and the best place for this is indeed in a database.

Then you have other problems which is that http is a rather slow mechanism for updating and maintaining records. Also the problem that you cannot push data out to the other clients but instead have to call a 'get' request to get the values of the table at any point.

Your problem is not overly difficult to solve in php and a database but it does require some more thought on your part as to how to solve it.


Offline cpsmith0191

  • Jr. Member
  • **
  • Posts: 68
    • caroleandcarl
Re: An abstract question concerning the capabilities of PHP
« Reply #3 on: August 24, 2017, 10:21:42 PM »
Matty, thanks for the input, I suppose the problem with 'apache' is that it isn't constrained by real world (web site) parameters, though it does make experimenting a lot easier. I simply got a do/while loop running and thought 'ah ha'. All isn't lost though as knowing that you got something similar going gives me hope. So back to SQL with a bit more thought given to my PHP.  I'm just beginning with getting, putting data into a site via blitzmax, but each program/player will be reading/writing from, to the website (cell in the data base), using the game software running on each computer. Well that's the theory. If I get anywhere I'll post the results, if only for entertainment value. Have fun cps
PS Just found an example by BlitzBot in the blitz archives that gives several pointers, well done to qube for preserving them.

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal