Jump to content

[SOLVED] real-time system: how to control state over multiple sessions?


alexweber15

Recommended Posts

got myself in a bit of a knot here trying to figure this out...

 

say i have a "real-time" system like an auction or game or whatever, something where i need to constantly know the state of the entire system, or at least parts of it.  lets assume an auction for the purpose of simplicity:

 

the auction ends in 24 hours and only 10 products are left.

 

how would i keep track of this info for all visitors?  i read about using singletons to store this kind of stuff but they are only as good as the user's session, so basically if i had 200 visitors at any given time then i'd have 200 seperate singleton instances... all containing the same information... sounds silly to me!

 

maybe i could write to a file and read off it, but either way thats still one file read for every user... i guess each new user has to get the information from somewhere but isn't there a way to have like an uber-global singleton that resides in the application's scope that every user could just read from or something?  or any way to not depend on active sessions to keep track of the system's state... know what i mean?

 

basically as far as i know when the last user logs out thats it, the application doesn't have a life of its own...  ???

Link to comment
Share on other sites

HTTP being a stateless protocol is a bitch.

 

 

For each client you have to create one or more instances of the class [to achieve what you're wanting to do].

 

 

"basically as far as i know when the last user logs out thats it, the application doesn't have a life of its own... "

 

 

Yup!

 

 

Although, you could always use a crontab or a scheduled task to make something happen every x days/hours/minutes/seconds or what ever.

Link to comment
Share on other sites

thanks, i guess its all good, since im gonna have to load the data everytime i might as well store it somewhere so no need for cronstuff just yet :)

 

Why wouldn't you pull this from a database?

 

overhead?  i'd hate to have to query the db every time someone new visited the site... how about caching or serializing the query?  or maybe reading from XML or something... better for a small amount of data and concurrent reads afaik!

 

but thanks its coming together a bit more now...

 

follow up:

 

so thumbs up for storing system state in a DB and/or File and retrieving it and creating a Singleton with the info every time a user signs in!  i guess the same applies to his personal preferences, although i could also just fetch the stuff when i perform the 'log in' query and stick it in a $_SESSION array or something...

Link to comment
Share on other sites

thanks, i guess its all good, since im gonna have to load the data everytime i might as well store it somewhere so no need for cronstuff just yet :)

 

Why wouldn't you pull this from a database?

 

overhead?  i'd hate to have to query the db every time someone new visited the site... how about caching or serializing the query?  or maybe reading from XML or something... better for a small amount of data and concurrent reads afaik!

 

 

Ever been to Google? You know when you type in their box, and they do an auto complete, those are database hits?

 

You know when you go to Ebay, and search for anything, there's tons of database hits?

 

You know most Oracle/Postgres databases can hit hundreds of thousands of transactions per second?

 

Overhead. lol..

 

 

 

Link to comment
Share on other sites

thanks, i guess its all good, since im gonna have to load the data everytime i might as well store it somewhere so no need for cronstuff just yet :)

 

Why wouldn't you pull this from a database?

 

overhead?  i'd hate to have to query the db every time someone new visited the site... how about caching or serializing the query?  or maybe reading from XML or something... better for a small amount of data and concurrent reads afaik!

 

 

Ever been to Google? You know when you type in their box, and they do an auto complete, those are database hits?

 

You know when you go to Ebay, and search for anything, there's tons of database hits?

 

You know most Oracle/Postgres databases can hit hundreds of thousands of transactions per second?

 

Overhead. lol..

 

 

 

 

 

:)

 

i guess they have just a tiny comparable advantage over me in terms of server capacity compared to my shared hosting  ;D

but yeah whereas mysql can handle tons of hits a second i'd rather do something like Zend does and store the application settings in an ini file or something instead and save that extra DB juice for when i need it ;)

Link to comment
Share on other sites

In some situations (actually fairly common with large sets of data) databases will be faster than files.  For example, imagine keeping a user database with 100k users in it.  Now put that in delimited flat file....

 

 

But if it's something simple like settings or something, then flat file will be fine ;p.

 

 

A DB is just a layer over a file system in a sense after all.

Link to comment
Share on other sites

  • 2 weeks later...

thanks, i guess its all good, since im gonna have to load the data everytime i might as well store it somewhere so no need for cronstuff just yet :)

 

Why wouldn't you pull this from a database?

 

overhead?  i'd hate to have to query the db every time someone new visited the site... how about caching or serializing the query?  or maybe reading from XML or something... better for a small amount of data and concurrent reads afaik!

 

 

as long as ur pulling plain text its rapid no matter how much ur pulling, thats what its there for, if u use files or sessions ur slowing it down more cos they arnt optamized for this stuff, a db uses a BIT WISE comparison to find what ur looking for wheras in a file youd have to search for expressions ect and then read lines.

 

Ever been to Google? You know when you type in their box, and they do an auto complete, those are database hits?

 

You know when you go to Ebay, and search for anything, there's tons of database hits?

 

You know most Oracle/Postgres databases can hit hundreds of thousands of transactions per second?

 

Overhead. lol..

 

 

 

Link to comment
Share on other sites

In some situations (actually fairly common with large sets of data) databases will be faster than files.  For example, imagine keeping a user database with 100k users in it.  Now put that in delimited flat file....

 

 

But if it's something simple like settings or something, then flat file will be fine ;p.

 

 

A DB is just a layer over a file system in a sense after all.

 

I've only used flat files for scripts I know only I'll be using. If you have a small site with just a few pages that gets popular one day and it's written with flat files, it's going to die. Disk access on a server is murder, try it some time build a flat file the best way you know how. Then build a database with the same number of entries. With a properly formed query a database will be faster every time. Once you have a server creating a new database takes less time then formatting a flat file. If your serving anyone other than yourself flat files should only be used for settings and code. Data storage should always be handled in a database.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.