Sign in to follow this  
snorky

[web] PHP Array of Objects Question

Recommended Posts

I'm creating an array of objects. For example in an RPG I want to load an array of races. The problem being I want these races to be available to every session that is currently under way. Pretend for simplicity there are only 2 races. Looking at it abstractly: RACES OBJECT RACES[Array] SESSION 1 User wants to view all races. SESSION 2 User wants to view one race. SESSION 5 User wants to select one race. I guess my question is do I want to make this array of races global or is there a better way to do this? (I don't want to have multiple arrays of races as it would be memory intensive.) Thank you GDnet in advance!

Share this post


Link to post
Share on other sites
With a "standard" setup, you cannot do this. With a common webserver setup Apache with fork or start a new thread for ever request. Every for gets it's own PHP instance and they cannot share data. The usual way to solve this is to write your own stand-alone server. A daemon that holds all the data and does the complicated work. Then let the PHP code running in Apache talk to your daemon. In this case, Apache+PHP is simply some HTTP glue between the client and your daemon.

In all honesty, it sounds a bit like premature optimisation. Get your game running first, then see if things like these really are the bottleneck. Then think about fixing it.

Share this post


Link to post
Share on other sites
Premature optimization lol. I think my brain tries to do that ALL the time. Anyway as I thought about it more I don't even need to keep them loaded so I'm on my way now, thanks for your reply thought Sander, much appriciated!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this