ryeguy Posted November 20, 2008 Share Posted November 20, 2008 I am making a PHP based game. For my item generation system, I have the base stats for each item TYPE defined and I want to know where I should store them. Since these are type definitions and not the generated items themselves, this data does not change unless I manually do it. For example, the oversimplified data might look like this: Item name - Min Attack - Max attack Knife - 3 - 5 Dagger - 5 - 7 And so on. When the item generation script is run, it loads this data and generates an attack range in between those values. What my problem is is I'm wondering how to store this data? My first instinct is to store it in the database, but then I would have to query it every time I generate an item, even though the data in there is NOT changing. I know that the database is normally the most overloaded thing on a php based game server, so I would rather not give it unnecessary load. What about XML files? Is the access speed decent enough? My optimal option would be to store it in a database, and have PHP store it in memory. Kind of like sessions, but for the entire server. This way, I get the ease of a database but I don't have to waste time requerying unchanging data. Is that even possible? Quote Link to comment https://forums.phpfreaks.com/topic/133546-best-data-storage-solution/ Share on other sites More sharing options...
revraz Posted November 20, 2008 Share Posted November 20, 2008 Why not use a DB and then just load the items in an array to use on the page? Quote Link to comment https://forums.phpfreaks.com/topic/133546-best-data-storage-solution/#findComment-694644 Share on other sites More sharing options...
premiso Posted November 20, 2008 Share Posted November 20, 2008 If you are afraid of the database being overloaded than xml should be fine, easy to manipulate/add to if necessary and easy to read. But I think that once the user has a connection to the database it will not matter running an extra 1 or 2 queries. Thats my opinion anyway. I think the database is the way to go. Quote Link to comment https://forums.phpfreaks.com/topic/133546-best-data-storage-solution/#findComment-694646 Share on other sites More sharing options...
ryeguy Posted November 20, 2008 Author Share Posted November 20, 2008 Why not use a DB and then just load the items in an array to use on the page? Because then the db is queried everytime the page is opened (thats all the script is for). The array doesn't persist between opening the page. Quote Link to comment https://forums.phpfreaks.com/topic/133546-best-data-storage-solution/#findComment-694650 Share on other sites More sharing options...
revraz Posted November 20, 2008 Share Posted November 20, 2008 And that's the purpose of the DB... Quote Link to comment https://forums.phpfreaks.com/topic/133546-best-data-storage-solution/#findComment-694660 Share on other sites More sharing options...
ryeguy Posted November 21, 2008 Author Share Posted November 21, 2008 And that's the purpose of the DB... Ok true, but querying the database puts unnecessary load on the database server. Since this is normally the bottleneck of a web based application, I'd like to avoid it if possible. Would this be a solution? http://us3.php.net/manual/en/book.memcache.php Quote Link to comment https://forums.phpfreaks.com/topic/133546-best-data-storage-solution/#findComment-695360 Share on other sites More sharing options...
Mark Baker Posted November 21, 2008 Share Posted November 21, 2008 Ok true, but querying the database puts unnecessary load on the database server. Since this is normally the bottleneck of a web based application, I'd like to avoid it if possible. Would this be a solution? http://us3.php.net/manual/en/book.memcache.php I can't really believe that this game is putting such an overhead on the database server that it can't handle one more query. However, if you are seriously concerned about this, APC might be better than memcache. You need to install a memcached server for memcache, while APC is a simple installation that works within the web server, and it is faster than memcache. Quote Link to comment https://forums.phpfreaks.com/topic/133546-best-data-storage-solution/#findComment-695380 Share on other sites More sharing options...
nadeemshafi9 Posted November 21, 2008 Share Posted November 21, 2008 store them as global variables if you work with them manualy Quote Link to comment https://forums.phpfreaks.com/topic/133546-best-data-storage-solution/#findComment-695392 Share on other sites More sharing options...
Mark Baker Posted November 21, 2008 Share Posted November 21, 2008 store them as global variables if you work with them manualyglobals variables are a) not particularly good practise b) not persistent I get the impression that ryeguy is after persistence Quote Link to comment https://forums.phpfreaks.com/topic/133546-best-data-storage-solution/#findComment-695432 Share on other sites More sharing options...
ryeguy Posted November 21, 2008 Author Share Posted November 21, 2008 Ok true, but querying the database puts unnecessary load on the database server. Since this is normally the bottleneck of a web based application, I'd like to avoid it if possible. Would this be a solution? http://us3.php.net/manual/en/book.memcache.php I can't really believe that this game is putting such an overhead on the database server that it can't handle one more query. However, if you are seriously concerned about this, APC might be better than memcache. You need to install a memcached server for memcache, while APC is a simple installation that works within the web server, and it is faster than memcache. Hmm, thanks that looks like what I'm looking for. And I haven't even really started programming the core of the game yet, I am just planning ahead. You're right, one query probably won't do much, but this item generation script isn't the only script were persistence would be helpful. Quote Link to comment https://forums.phpfreaks.com/topic/133546-best-data-storage-solution/#findComment-695572 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.