| | |
"interactive refresh" ?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Dec 2007
Posts: 3
Reputation:
Solved Threads: 0
How should I implement "interactive refresh" (I don't even know how I should call it) where one visitor's action (klicking a link, submit button etc. - everything will do) activates page refreshing of other visitors on the same page?
I know how to implement an automatic, periodic refresh but I would like it to refresh only when someone has really made a change to the page (it would be kind of interactive multiuser application).
If it's not possible with php, is there some other way?
- Lennart
I know how to implement an automatic, periodic refresh but I would like it to refresh only when someone has really made a change to the page (it would be kind of interactive multiuser application).
If it's not possible with php, is there some other way?
- Lennart
Umm..I dont think its possible(I am quite sure its not possible!).. When a user opens a page on your site, hes opening an instance of your page in his browser and its different for different users. Why do you want something like this btw ?
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
Why would you need something like this?
If my post is useful please add to my reputation.
Thanks.
Ajtrichards Web Solutions | http://www.ajtrichards.co.uk
Retenovate | http://www.retenovate.com
Thanks.
Ajtrichards Web Solutions | http://www.ajtrichards.co.uk
Retenovate | http://www.retenovate.com
Building a stateful web application is possible, but not feasible for most application scenarios. As for why a person may want such a thing? LOTS of reasons. An obvious example is a browser-based chat application. You want all members of the chat to see all messages entered as close to real-time as possible.
The most common and easy to implement solution is to build an "AJAX" solution. If you don't know what AJAX is, search here in the forums or just Google it. In short, it is a way for javascript running in the browser to make separate HTTP/HTTPS requests to your web server. It can do this "in the background" (asynchronously) while the user continues to use the browser application.
So while not truly stateful, you can build a web app that appears to be stateful by having an AJAX request check frequently for server-side changes and then update the client browser accordingly. This could mean that the AJAX request actually retrieves the new information and dynamically changes the page contents or it could mean you fire a page refresh.
Depending on the number of simultaneous users you need to support and the power of your server hardware and bandwith, you can set your AJAX request to fire every 5 seconds or whatever makes sense for your app. You may be able to get away with 3 seconds, but 1 or 2 is simply asking a lot of a browser/webserver relationship. If you code it correctly, though, it won't matter if the request takes 10 seconds to return--you'll only set the timer for the next request AFTER the last request returns.
You may think to yourself, "gee, checking every 5 seconds just to see IF something changed seems really inefficient". But consider that it's something browsers and webservers do well and it's less expensive and more scalable than having every browser hold an open socket continuously.
I gave the example of a chat application. That is probably a good model for you to look at if you need an example. A search for +AJAX +chat +browser should give you some examples.
http://www.google.com/search?q=%2BAJ...3,IBMA:en&aq=t
The most common and easy to implement solution is to build an "AJAX" solution. If you don't know what AJAX is, search here in the forums or just Google it. In short, it is a way for javascript running in the browser to make separate HTTP/HTTPS requests to your web server. It can do this "in the background" (asynchronously) while the user continues to use the browser application.
So while not truly stateful, you can build a web app that appears to be stateful by having an AJAX request check frequently for server-side changes and then update the client browser accordingly. This could mean that the AJAX request actually retrieves the new information and dynamically changes the page contents or it could mean you fire a page refresh.
Depending on the number of simultaneous users you need to support and the power of your server hardware and bandwith, you can set your AJAX request to fire every 5 seconds or whatever makes sense for your app. You may be able to get away with 3 seconds, but 1 or 2 is simply asking a lot of a browser/webserver relationship. If you code it correctly, though, it won't matter if the request takes 10 seconds to return--you'll only set the timer for the next request AFTER the last request returns.
You may think to yourself, "gee, checking every 5 seconds just to see IF something changed seems really inefficient". But consider that it's something browsers and webservers do well and it's less expensive and more scalable than having every browser hold an open socket continuously.
I gave the example of a chat application. That is probably a good model for you to look at if you need an example. A search for +AJAX +chat +browser should give you some examples.
http://www.google.com/search?q=%2BAJ...3,IBMA:en&aq=t
Last edited by Troy; Dec 16th, 2007 at 12:35 am.
You could use the jQuery Javascript library that allows you to create simple Ajax interactions.
You can download a plugin that will send AJAX requests per second, 2 second, whatever you want.
You can get it here:
http://www.ajtrichards.co.uk/heartbeat
You can download a plugin that will send AJAX requests per second, 2 second, whatever you want.
You can get it here:
http://www.ajtrichards.co.uk/heartbeat
![]() |
Other Threads in the PHP Forum
- Previous Thread: Error loading data from database
- Next Thread: Regex Whitespace
| Thread Tools | Search this Thread |
.htaccess alerts apache api archive array autocomplete beginner binary broken cakephp checkbox class cms code convert cron curl database dataentry date display duplicates dynamic echo email emptydisplayvalue error execute explodefunction file files firstoptioninphpdroplist folder form forms function functions google hack href htaccess html htmlspecialchars image include insert ip javasciptvalidation javascript joomla keywords limit link login mail matching menu methods mlm multiple mysql network object oop paypal pdf php problem query radio random recursion recursive redirect remote script search securephp server sessions shot sms source space sql subscription syntax system table tutorial tutorials update upload url validator variable video web youtube






