HartleySan Posted July 10, 2012 Share Posted July 10, 2012 I was looking at the following page today about the new WebSockets API: http://code.google.com/p/phpwebsocket/ I understand all the client and server code, but I couldn't understand the following step in the procedure below the code: 2. From the command line, run the server.php program to listen for socket connections. How do I do this? Where's the command line for an Apache server? How do you run a PHP script from the command line? After performing this step, will the PHP script run forever on the server, making it always available when a WebSocket is needed, or is this a step that must be executed every time I want to open a socket for bi-directional communication? Thank you all in advance. Link to comment Share on other sites More sharing options...
Larry Posted July 11, 2012 Share Posted July 11, 2012 How you run PHP from the command line really depends upon what OS you're running and how you installed PHP. Yes, if I read that code correctly, the server.php script will continue to run to listen for incoming connections. Link to comment Share on other sites More sharing options...
HartleySan Posted July 12, 2012 Author Share Posted July 12, 2012 Well, let's say that I'm using a hosting service, and the extent of my access to admin stuff is the cPanel. What then? Link to comment Share on other sites More sharing options...
Paul Swanson Posted July 12, 2012 Share Posted July 12, 2012 You might have to ask your hosting service to execute that script for you. You could ask for telnet access, but I wouldn't expect them to allow it since it would make it easier for you to access other customer's folders on the same server. 1 Link to comment Share on other sites More sharing options...
HartleySan Posted July 12, 2012 Author Share Posted July 12, 2012 Yeah, I was thinking the same thing. Thanks, Paul. Link to comment Share on other sites More sharing options...
Antonio Conte Posted July 12, 2012 Share Posted July 12, 2012 Want to point out the use, Jon? Never seen this before. What can you do with it? Link to comment Share on other sites More sharing options...
HartleySan Posted July 13, 2012 Author Share Posted July 13, 2012 It's a new API to the HTML5 draft, but basically, it allows for bi-directional communication and asynchronous messaging. In essense, it allows for more dynamically responsive applications like chat services, video conversations, chess games that respond instantly to an opponent's move, etc., etc. It really is a great thing, actually, as Java has had asynchronous messaging forever, but it has always been missing from HTML. I imagine that in time it will have as big an effect on the Web as Ajax has up till now. I built a rudimentary chat application the other day using the WebSocket API and Ajax long polling for non-HTML5 browsers. It wasn't as hard as I thought. Link to comment Share on other sites More sharing options...
HartleySan Posted July 13, 2012 Author Share Posted July 13, 2012 For testing purposes, I'd like to be able to install the server PHP script using XAMPP. Does anyone know how to do that? Thanks. Link to comment Share on other sites More sharing options...
HartleySan Posted July 13, 2012 Author Share Posted July 13, 2012 Antonio, I found the following good site dedicated to explaining the new API: http://www.websocket.org 1 Link to comment Share on other sites More sharing options...
Antonio Conte Posted July 13, 2012 Share Posted July 13, 2012 Looks like the best of both worlds. A full-duplex, handshaken, non-reliable way of sending messages. Sounds like a combination of TCP and UDP without the shortcomings. Maybe I'll start creating a live football match part of my website or something? Would be a great way of keeping my fans updated under a match. Link to comment Share on other sites More sharing options...
HartleySan Posted July 13, 2012 Author Share Posted July 13, 2012 Yes, exactly. "The best of both worlds." I like that. In a couple years, as this API gets wider browser support and recognition, I have no doubt that it'll become the new standard for websites/Web apps, similar to what Ajax sites are now compared to older-style sites. I can already thing of a million applications for this thing. Basically, this is a big part of the puzzle in trying to make the move to Desktop-like apps, games, etc. Link to comment Share on other sites More sharing options...
Recommended Posts