Click to See Complete Forum and Search --> : Application Objects in PHP
L0phtpDK
04-29-2006, 09:18 PM
Hey Everyone,
Looking for a way to do Application Objects (like that of ASP (http://www.w3schools.com/asp/asp_applications.asp)). Not to sure if that would be the correct name for it in PHP... but you could also call them server-wide variables. I want to avoid using MySQL for these calculations.
- Eric
rch10007
04-29-2006, 09:21 PM
look at this and see if it's what youa re talking about:
http://www.php.net/manual/en/language.variables.predefined.php
L0phtpDK
04-29-2006, 09:30 PM
$_ENV and $_SERVER looks promising... I haven't run a test on them yet.
But... lets say I wanted to have an array of objects on my server's memory (ie: locations to characters on a game map... seen by all users/clients), what one would I use?
EDIT: to make better sense... if I had two scripts (A.php and B.php), which declaration would allow the both scripts to see the variable.
Also, I ran across this: http://zez.org/article/articleview/46/1/
Are they asking to RE-compile the php binary before I use it? And isn't using that method a little dangerous... ?
rch10007
04-29-2006, 09:36 PM
using $_SESSION['variable'] or $_COOKIE['variable'] would allow you to pass the variable to whatever page you wanted to. make sure to use session_start() at the top of any pages that use session variables.
NogDog
04-29-2006, 09:45 PM
Yeah, it sounds like something you'd want to use sessions for. See http://www.php.net/manual/en/ref.session.php if you want to learn more (perhaps more than you want ;) ).
L0phtpDK
04-29-2006, 09:47 PM
Doesn't the $_COOKIE declaration send the varable through the network?
I'm looking for something that is stored locally on the server's RAM.
rch10007
04-29-2006, 09:48 PM
yes, but that may be important if you are going to need different variables set for each user.
L0phtpDK
04-29-2006, 09:50 PM
True - But these are global variables... All the users need the see the same data.
rch10007
04-29-2006, 09:53 PM
go with $_SESSION[''] then, I was just pointing out the cookie variable in case you are going to need to pull info from an individual user. but if you don't need to pass info back and forth, don't.
Daniel T
04-30-2006, 12:07 AM
True - But these are global variables... All the users need the see the same data.Then perhaps this is betters suited to a text file (if you can't use MySQL)? I imagine you could have access to all users' data if you had their SESSIDs, but it wouldn't be very practical...
L0phtpDK
04-30-2006, 12:13 AM
That was another idea... but I'm looking for speed.
I think ASP may be the way to go on this one... because PHP just doesn't support this (with out a System V extension... which is not available on Windows... )
meh....
Daniel T
05-01-2006, 12:05 AM
... but I'm looking for speed ... because PHP just doesn't support this
You could simply write some functions to send/retrieve variables from files. This wouldn't be slower than ASP, because that's what ASP would be doing anyways. It has to be storing those varibales SOMEWHERE ;) (hint: temp files)
L0phtpDK
05-01-2006, 08:18 PM
They do store them somewhere... It stores it in the RAM.
rch10007
05-01-2006, 09:03 PM
if RAM is the only storage facility, I hope you got lots of it!
L0phtpDK
05-02-2006, 02:46 AM
Well you're missing the idea.
Of COURSE i'm going to save it to an SQL database... but why flood it with a bunch of minute details when I could send it one large one (buffer the small details into a RAM)? Wouldn't that be more effecient? (and these are minor details... so if the data is lost, no big deal)
Stephen Philbin
05-02-2006, 08:22 AM
If you're on a Windows box, they you'd probably be best using the .Net framework anyway.
If you're looking to reduce speed that much and it's "no big deal" if these variables are lost, then I'd suggest you ditch them all together. It's just an unnecessary work for the systems resources.
If you're doing something like making an online multi player game (which is what it sounds like), then you don't want to be using either .Net or PHP. You'd want to be building a proper server application and client application in something like C/C++ (seeing as speed is of the essence) and have them connect via a stateful protocol (possibly also custom built).
L0phtpDK
05-02-2006, 11:54 AM
Very true Stephen.
I plan on doing that, but we're still prototyping so I'm trying to make the development time as quickly as possible (2 weeks from concept to release). This is only an attempt to gain more VC for the project.