Kryptix Posted May 7, 2010 Share Posted May 7, 2010 So, I love the idea of Ajax and I really want to get into it. But I have a few issues. Say for example if I have a users table with 30,000 users registered, and a column `online` which dictates whether they're online or not... I then have a Ajax script saying something like, "There's currently 38 users online!" updating every second or so on a timer. This worked fine when I tested myself but as soon as you have 38 people on the site, that then turns into 38 queries a second... Which sent the CPU to 100%. So the only way I can think of doing it, is by having a table dedicated to Ajax with stats like that updating every second, and then have the users simply query one entry rather than 30,000. It makes sense, but is there an easier way? If that's correct, how do you go about running the query every second? Is that even the right way to do this? Maybe you have a table with columns `online_count` and `time`, each time Ajax queries for the count it checks to see if it's more than a second old and if so, run the script to update it? Am I thinking straight or am I way off? Quote Link to comment https://forums.phpfreaks.com/topic/200982-ajax-few-noob-questions/ Share on other sites More sharing options...
trq Posted May 7, 2010 Share Posted May 7, 2010 Why is it so important that your users know who is online accurate to the second? Quote Link to comment https://forums.phpfreaks.com/topic/200982-ajax-few-noob-questions/#findComment-1054585 Share on other sites More sharing options...
Kryptix Posted May 7, 2010 Author Share Posted May 7, 2010 Why is it so important that your users know who is online accurate to the second? That's not the point, I'm using it as an example... Quote Link to comment https://forums.phpfreaks.com/topic/200982-ajax-few-noob-questions/#findComment-1054750 Share on other sites More sharing options...
Alex Posted May 7, 2010 Share Posted May 7, 2010 In most cases it's not practical to make ajax calls that quickly, especially if you're using Apache. Maybe you should look into some push technology like long pooling, you can start here: http://en.wikipedia.org/wiki/Push_technology Quote Link to comment https://forums.phpfreaks.com/topic/200982-ajax-few-noob-questions/#findComment-1054826 Share on other sites More sharing options...
Kryptix Posted August 24, 2011 Author Share Posted August 24, 2011 Anyone else? Quote Link to comment https://forums.phpfreaks.com/topic/200982-ajax-few-noob-questions/#findComment-1261130 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.