Re: [PHP] Sessions VS MySQL



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?
.



Relevant Pages

  • Re: Winning a POKER
    ... Don't play LONG HOURS. ... Cash game players rule, ... It's hard to stay focused when you put long sessions in, plus, one ...
    (rec.gambling.poker)
  • Re: Average Win/Loss
    ... actually folding 'sometimes' within the past few sessions. ... player can run bad for a long time, ... huge short-term variance, are you saying that NL is less? ... It's hard to accurately estimate variance in NL, since game conditions ...
    (rec.gambling.poker)
  • Re: After almost 4 month loosing - need advice
    ... At first, i thought i'm a winning player, but now i'm really not sure. ... The downswing happened at exactly the same time that I felt that my understanding of the game had taken a quantum leap for the better. ... No loosing months and 75% of my sessions are winning ones. ... Perhaps a poker playing friend can help. ...
    (rec.gambling.poker)
  • Re: NWN
    ... i played entire 3-4 hour sessions without a single fight. ... > ALL three ads depicting imagery of characters in combat. ... What's a more hack and slash game than ... non-combat game play in them. ...
    (comp.sys.ibm.pc.games.rpg)
  • Mass Effect - rant
    ... Not only would it appear to have a huge bug that can corrupt your progress at any time, but the actual auto-save points seem to be hours apart in some cases. ... Having got used to auto-saves in other games and with it being an effort to pause the game to get to the save menu etc.. ...
    (uk.games.video.xbox)