This is a discussion on Sessions VS MySQL within the PHP General forums, part of the PHP Programming Forums category; I've recently begun work on a web-based RPG game with some friends, and have recently been thinking about ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I've recently begun work on a web-based RPG game with some friends, and have
recently been thinking about the best solution for loading and saving persistent variables like player life/stats and other information. I am both familiar with sessions and mysql for saving and loading variables, and that's not my question, but I am instead interested in which method would be more efficient to use. If the data is getting reloaded on each individual page, would it be more efficient on the system hosting the game to save certain numbers and variables in a session, or to reaccess the database each time it needs those numbers. My biggest concern with using sessions, is if someone were to exit the browser mid saves to the database, all information would be lost. Since it is web-based, there is no real way for me to be able to expect everyone to follow certain procedures to load/save, and I would really like to stay away from that as well, as it's not as user-friendly and intuitive as an auto-save feature. I guess my main question here is, are there ways to auto-save and guarantee data wouldn't be lost without having to load, read, write, and close a connection to mysql on each page load? I appreciate any tips, insight, thoughts, stories, or help in absolutely any fashion that I can get. Even a tip of a nature outside my question related to my project would be great. it's my first project of this kind, and I'd like to avoid any problems I can, so I'm putting a lot of forethought into it all. Also, I'm the only coder, so to have to go back and rewrite a ton of code from one save method to another is just way too much work. |
|
|||
|
Matt Fielding wrote:
> I've recently begun work on a web-based RPG game with some friends, and > have > recently been thinking about the best solution for loading and saving > persistent variables like player life/stats and other information. I am > both > familiar with sessions and mysql for saving and loading variables, and > that's not my question, but I am instead interested in which method > would be > more efficient to use. If the data is getting reloaded on each individual > page, would it be more efficient on the system hosting the game to save > certain numbers and variables in a session, or to reaccess the database > each > time it needs those numbers. > > My biggest concern with using sessions, is if someone were to exit the > browser mid saves to the database, all information would be lost. Since it > is web-based, there is no real way for me to be able to expect everyone to > follow certain procedures to load/save, and I would really like to stay > away > from that as well, as it's not as user-friendly and intuitive as an > auto-save feature. I guess my main question here is, are there ways to > auto-save and guarantee data wouldn't be lost without having to load, read, > write, and close a connection to mysql on each page load? Seems as you don't know if the user will close the browser between page loads, AND to be user friendly so that they don't have to click a save button, the ONLY way would be to save the game every time the page loads. So save all data to the database each page run. This will also help in that other players will beble use that data. Say if you needed the top scoring 10 players for example, the data is already saved in the database so it will be easy to find that out, with the most up-to date player data. Darren > > I appreciate any tips, insight, thoughts, stories, or help in absolutely > any > fashion that I can get. Even a tip of a nature outside my question related > to my project would be great. it's my first project of this kind, and I'd > like to avoid any problems I can, so I'm putting a lot of forethought into > it all. Also, I'm the only coder, so to have to go back and rewrite a > ton of > code from one save method to another is just way too much work. > |
|
|||
|
On Wed, May 30, 2007 4:00 am, Matt Fielding wrote:
> I've recently begun work on a web-based RPG game with some friends, > and have > recently been thinking about the best solution for loading and saving > persistent variables like player life/stats and other information. I > am both > familiar with sessions and mysql for saving and loading variables, and > that's not my question, but I am instead interested in which method > would be > more efficient to use. If the data is getting reloaded on each > individual > page, would it be more efficient on the system hosting the game to > save > certain numbers and variables in a session, or to reaccess the > database each > time it needs those numbers. > > My biggest concern with using sessions, is if someone were to exit the > browser mid saves to the database, all information would be lost. > Since it > is web-based, there is no real way for me to be able to expect > everyone to > follow certain procedures to load/save, and I would really like to > stay away > from that as well, as it's not as user-friendly and intuitive as an > auto-save feature. I guess my main question here is, are there ways to > auto-save and guarantee data wouldn't be lost without having to load, > read, > write, and close a connection to mysql on each page load? > > I appreciate any tips, insight, thoughts, stories, or help in > absolutely any > fashion that I can get. Even a tip of a nature outside my question > related > to my project would be great. it's my first project of this kind, and > I'd > like to avoid any problems I can, so I'm putting a lot of forethought > into > it all. Also, I'm the only coder, so to have to go back and rewrite a > ton of > code from one save method to another is just way too much work. There are several approaches you could take, and you may even want to consider a mix of approaches. The first question is how much this has to scale, and how much data is stored per user? Becuase if you need a Meg per user and expect to scale out to XBox, then you've got a very different problem than if you expect you and your 10 buddies to be playing this RPG for years on end, but that's about it... You may want to classify data into broad buckets such as: Transient Data - store it in the cookie value Active Data - store it in session Permanent Data - auto-save to database Background Data - the "game" state as opposed to the individual user state You might choose to auto-save at certain mile-markers, such as every time the player gains an experience point, or achieves a specific goal in the game, or both. (Got the key, rescued the princess, whatever) Probably be best to have a simple "save" function to call, and call it as often as needed. You may also need to consider solving a "Race Condition" within the saved states -- At some point, you have to purge a saved state if a user is "gone" long emough and the others had to move forward... Either that, or suddenly both Biblo *and* Gandalf has "the key" and your game is all messed up... There may be some OpenSource RPG engines you could research, or even link in to PHP as a custom extension -- or throw it into PECL if enough users want to write RPGs in PHP :-) -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? |
|
|||
|
As far as scalability goes, there's actually a game we're referencing a lot
to help us make it work at the get go called Kingdom of Loathing ( http://www.kingdomofloathing.com ). This game seems to have on average around 1,000-1,500 users on at any given time. I've noticed when visiting the page also, that is sends you to a random mirror of the site such as www2..., www3..., etc.. I'm not sure if those shows that it's directing people to various servers for the website, and that the database is possibly stored on one server by itself. This seems a bit bulky a solution for an online text/2d low res image rpg game, even with 1,000 users playing simultaneously. The point of saving only when I need to I get, and was planning to implement. Such things as exploring around the game world, and, well, that's all really, don't need to be saved as you'll start at the main location each time you log in, but other things like battle, buying/selling/upgrading items and inventory, and quest locations on the map, all need to be saved. I guess one of my bigger concerns about saving is if it would seem natural or strange to have it only save after the end of each battle, because the way the battle system is planned to work is that you attack, it loads the page, says how much dmg you did and the enemy did, then you may have to attack again, loading the page howveer many more times is needed until you die, or the enemy dies. There will be a function to run built in, but aside from that the only other way to get out is to exit the browser. It seems a bit cumbersome to have to access the db everytime an attack takes place, but at the same time the player will be limited to a number of "moves" per day, to make the game more fun, and help the server from dying. From what I recall, mysql database calls take only .002 seconds, or something very quick like that, so I suppose I shouldn't be too worried about the database overloading from people using it, or should I? That's really one of my main concerns. Anyways, thanks for all the help and input so far, it's greatly appreciated. |