alexweber15 Posted September 24, 2008 Share Posted September 24, 2008 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... ??? Quote Link to comment https://forums.phpfreaks.com/topic/125641-solved-real-time-system-how-to-control-state-over-multiple-sessions/ Share on other sites More sharing options...
CroNiX Posted September 25, 2008 Share Posted September 25, 2008 Why wouldn't you pull this from a database? Quote Link to comment https://forums.phpfreaks.com/topic/125641-solved-real-time-system-how-to-control-state-over-multiple-sessions/#findComment-649978 Share on other sites More sharing options...
corbin Posted September 25, 2008 Share Posted September 25, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/125641-solved-real-time-system-how-to-control-state-over-multiple-sessions/#findComment-650070 Share on other sites More sharing options...
alexweber15 Posted September 25, 2008 Author Share Posted September 25, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/125641-solved-real-time-system-how-to-control-state-over-multiple-sessions/#findComment-650436 Share on other sites More sharing options...
keeB Posted September 26, 2008 Share Posted September 26, 2008 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.. Quote Link to comment https://forums.phpfreaks.com/topic/125641-solved-real-time-system-how-to-control-state-over-multiple-sessions/#findComment-651103 Share on other sites More sharing options...
alexweber15 Posted September 26, 2008 Author Share Posted September 26, 2008 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 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 Quote Link to comment https://forums.phpfreaks.com/topic/125641-solved-real-time-system-how-to-control-state-over-multiple-sessions/#findComment-651224 Share on other sites More sharing options...
corbin Posted September 26, 2008 Share Posted September 26, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/125641-solved-real-time-system-how-to-control-state-over-multiple-sessions/#findComment-651491 Share on other sites More sharing options...
alexweber15 Posted September 26, 2008 Author Share Posted September 26, 2008 true enough! Quote Link to comment https://forums.phpfreaks.com/topic/125641-solved-real-time-system-how-to-control-state-over-multiple-sessions/#findComment-651513 Share on other sites More sharing options...
nadeemshafi9 Posted October 10, 2008 Share Posted October 10, 2008 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.. Quote Link to comment https://forums.phpfreaks.com/topic/125641-solved-real-time-system-how-to-control-state-over-multiple-sessions/#findComment-661921 Share on other sites More sharing options...
DyslexicDog Posted October 10, 2008 Share Posted October 10, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/125641-solved-real-time-system-how-to-control-state-over-multiple-sessions/#findComment-661968 Share on other sites More sharing options...
alexweber15 Posted October 11, 2008 Author Share Posted October 11, 2008 thanks for the tip dude! Quote Link to comment https://forums.phpfreaks.com/topic/125641-solved-real-time-system-how-to-control-state-over-multiple-sessions/#findComment-662435 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.