943,751 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1341
  • PHP RSS
Dec 15th, 2007
0

"interactive refresh" ?

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lesalmin is offline Offline
3 posts
since Dec 2007
Dec 15th, 2007
0

Re: "interactive refresh" ?

Umm.. are you asking whether it is possible to refresh other visitor's page when 'one' of the visitor clicks a link/submits a form/.. ??
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Dec 15th, 2007
0

Re: "interactive refresh" ?

Yes, that's the idea. Or "when ANY of the visitors of the same page clicks a link/button" to be exact. Am I crazy when even dreaming of something like that :-]
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lesalmin is offline Offline
3 posts
since Dec 2007
Dec 15th, 2007
0

Re: "interactive refresh" ?

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 ?
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Dec 15th, 2007
0

Re: "interactive refresh" ?

Why would you need something like this?
Reputation Points: 15
Solved Threads: 17
Junior Poster
phper is offline Offline
189 posts
since Nov 2006
Dec 16th, 2007
1

Re: "interactive refresh" ?

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
Last edited by Troy; Dec 16th, 2007 at 12:35 am.
Reputation Points: 36
Solved Threads: 6
Posting Whiz
Troy is offline Offline
354 posts
since Jun 2005
Dec 17th, 2007
0

Re: "interactive refresh" ?

Thanks. I think I can get on with it now.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lesalmin is offline Offline
3 posts
since Dec 2007
Jan 7th, 2008
0

Re: "interactive refresh" ?

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
Reputation Points: 15
Solved Threads: 17
Junior Poster
phper is offline Offline
189 posts
since Nov 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Error loading data from database
Next Thread in PHP Forum Timeline: Regex Whitespace





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC