Re: Sessions VS MySQL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux