views:

294

answers:

3

How feasible is it to translate this Ruby websocket server to PHP?

http://github.com/gimite/web-socket-ruby/blob/master/lib/web_socket.rb

I know a little bit of Ruby and a decent amount of PHP, thought I've never done socket programming. I'd like to build a chat app on top of what gimite has put up on git, but all my sites are in PHP. How hard do you guys think it would be to rewrite those 300 lines in PHP?

Is it possible? If it is, will it be difficult? What would be the most difficult part? Would PHP take any performance hits? Am I better off trying to integrate that Ruby server into my PHP site by moving session management into the DB instead of attempting to translate it?

Thank you for your time.

+1  A: 

For someone who knows what they're doing, it's quite feasible. There's nothing magical about Ruby's sockets library.

Azeem.Butt
A: 

The difficult part is that PHP is not typically long-running. You'd likely end up writing it to run under the php command line interpreter.

Session handling will be interesting, no matter where you're running it. This looks like it'd use a side channel and not necessarily know or have access to the browser's session cookies.

Jim Zajkowski
I see.. so having to run it under the command line interpreter I would essentially have to code the DB session management layer regardless of whether it's Ruby or PHP...? In which case it might be easier to just add that part to the Ruby server instead of coding both in PHP....?
Serhiy
+1  A: 

Here is a basic websocket implementation in PHP:

http://code.google.com/p/phpwebsocket/

also available in github

George Nava