Page 1 of 1

PHP + Sockets, Real time look and feel?

Posted: Fri Mar 04, 2005 1:25 pm
by kastion
Well, I'm trying to develop a certain area on my website in such a way that you don't need to refresh the page, and clicking links etc don't refresh the page. PHP being preprocessor server-side language I'm wondering if that's even possible. I've been reading about sockets, and was testing use with TCP port 80. Yeah sure I can open a socket send some info to my page and close it. But is it possible to keep the socket open and run php functions from that page without refreshing it?

Here's an example of what I mean. I have a page lets call it realtime.php,
inside I have a bunch of functions I want to use. The entire php script is wrapped in a while loop, which listens for TCP input on port 80. The page has a div with id "myDiv". Every time the user sends some input, it changes the innerHtml of "myDiv" based on the input from the user. (runs a different function for different input and changes innerHtml)

Is this possible? Or because PHP is a preprocessor server-side language will my page not load at all and be in an infinite loop waiting for input it will never receive?

Are there any other options to get this kind of real time feel in a php/mysql page?

Posted: Fri Mar 04, 2005 1:29 pm
by feyd
I don't see a point.. Keep a log of what to display in a database, update it, and display all records needed when they ask something to happen. Clicking a link would make it refresh anways..

Posted: Fri Mar 04, 2005 1:31 pm
by kastion
Well I'll be a little more specific, clicking the link would have an onclick function(sending a string or number with a socket function), and the reason I don't want it to refresh is because it's a php rpg.

Posted: Fri Mar 04, 2005 1:34 pm
by The Monkey
kastion wrote:Well I'll be a little more specific, clicking the link would have an onclick function(sending a string or number with a socket function), and the reason I don't want it to refresh is because it's a php rpg.
All of the online RPG games I've played refresh. Just a thought.

Posted: Fri Mar 04, 2005 1:38 pm
by kastion
The Monkey wrote:
kastion wrote:Well I'll be a little more specific, clicking the link would have an onclick function(sending a string or number with a socket function), and the reason I don't want it to refresh is because it's a php rpg.
All of the online RPG games I've played refresh. Just a thought.
Well I'm trying to do my own thing. And I want to be able to show animations and update stats without page refreshes, I could go ahead and use flash but 1) I don't know how 2) everyone tells me actionscript blows.

Posted: Fri Mar 04, 2005 2:12 pm
by kastion
http://www.sitepoint.com/print/no-refresh-links :!:

I think I can do what I was trying by using this method ^ and changing innerHtml content of a div with php functions. Much simpler than I thought, not so hard on the server, much more feasible that trying to do that with sockets.

Posted: Fri Mar 04, 2005 2:12 pm
by andre_c
You might try using javascript's XmlHttpRequest object (or i think that's what it's called), search for it on google

Posted: Fri Mar 04, 2005 3:01 pm
by timvw
at http://timvw.madoka.be you can see a "live" example of that ;) (the chatbox is updated every 60 Seconds withouth reloading the whole page)

source at http://timvw.madoka.be/programming/php/chat_server.txt
http://timvw.madoka.be/programming/php/chat_client.txt

Posted: Sun Mar 06, 2005 11:27 am
by patrikG
JSpan can help you with that: http://jpspan.sourceforge.net

Posted: Sun Mar 13, 2005 5:26 pm
by kastion

Posted: Sun Mar 13, 2005 5:35 pm
by infolock
i have only one word for you

iFrame