[Help] Simple websocket chat?

software development

#1

So I’ve been interested in web sockets. I’ve come across NODEJS but have found it’s pretty complex to get all setup, so I’ve searched around more and come to this: http://www.flynsarmy.com/2012/02/php-websocket-chat-application-2-0/

I downloaded the “Final Script” which was a few files, it looked pretty simple to get started with but I still can’t get it.

So I have putty as an SSH client, and I’m not even sure how to get my “server.php” file to work.

I connect to my website, enter username and password, it welcomes me and says “Any malicious and/or unauthorized activity is strictly forbidden.
All activity may be logged by DreamHost Web Hosting.”

so I’m told that I have to type: php5 path/to/server.php
Okay, I type that and have a “-bash: php5: command not found”

Next I think: "okay, mabye I should just type ‘php’ instead of ‘php5’"
So I do and it causes my putty client to stop allowing commands to be entered into the server (but I can still type them, I just don’t get any responses/feedback from the session). So it’s basically frozen.

Am I doing something wrong?


#2

If your terminal is still hung try breaking out of the command with ctrl-c.

/usr/local/php53/bin/php path/to/server.php

for php 5.3… on dreamhost you need /usr/local/php53/bin/php instead of php5


#3

Are you on VPS or dedicated?


#4

Oh thanks!

I had no idea that’s what the problem was. This is my first time using the terminal on my web server. Whenever I close my putty window on my computer, the server shuts down, and I have to open up a new putty window, connect, and run the script again in order to have the server running. How do I enable and disable the server through terminal without it shutting down when I close my window?

I’m not on a VPS so I guess dedicated?


#5

You could probably use screen

$ screen
$ [run commands]
press CTRL+A CTRL+D to return to your previous shell and logout as usual.
$exit

Next time you log in, reattach to the screen with:
$ screen -DD -r
and close it with:
$ exit


#6

If you don’t know, you are probably on a shared hosting server. (And I checked — you are.)

Network servers, like the WebSocket server you’re trying to run, are not permitted shared hosting accounts. This isn’t what is causing the issues you’re running into, but it’s an important point that I figured I’d make here. :slight_smile:

As far as the behavior you’re seeing, that’s expected — the script you’re running doesn’t go into the background when it’s started. You’d need to have some sort of system for running this script in the background if you were to use it on a VPS or dedicated server.


#7

Thanks for the info. Is screen basically the terminal equivalent of alt-tab?

So if I did have a VPS (which I have been thinking about getting), would that screen command be that system that I use?


#8

screen is a UNIX utility that basically acts as a sort of virtual tabbed terminal inside a terminal, and lets you detach from those terminals while they’re running and come back to them later.

It’s not a recommended method of deploying a server (you’re better off writing the server such that it forks into the background automatically), but it’s handy as a way to keep things running.


#9

I’ll just reiterate that you can’t do what you’re trying to do as it infringes the TOS for shared servers (that’s why I asked first).

So I better answer you query again.

Yes :stuck_out_tongue:


#10

Okay, well at least I know what to do for when I get a VPS or Dedicated.