6

I have a GoDaddy Linux hosting , any idea how do I run a websocket server for my HTML5 web app ? Any other recommendation ?

I know VPS can do it, but it is costly , any PaaS solution ?

Neil
  • 5,919
  • 15
  • 58
  • 85
  • Are you trying to run a PHP listening server on GoDaddy? Or are you trying to run a WebSocket in Javascript? – user0000001 Jan 25 '13 at 06:58
  • If you are using vps you can take a look at something like [node.js](http://nodejs.org/) and [socket.io](http://socket.io/). – Edward A Jan 25 '13 at 08:49
  • @Chris Yes I am trying to listen in the PHP hosting I already bought. Writing clients in JS is relatively easier , given that all latest browsers support. – Neil Jan 25 '13 at 09:13
  • I know VPS is an option , but it is costly. Any PaaS solution ? – Neil Jan 25 '13 at 09:14
  • Pubnub is a great real time message service http://www.pubnub.com/ depending on what you are trying to do. Without the need for VPS – Craig Blagg Jan 25 '13 at 09:21

3 Answers3

1

If you have a shared hosting plan, you will very likely not be able to access sockets, thus making it impossible to use the WebSocket API.

HartleySan
  • 7,404
  • 14
  • 66
  • 119
1

You're going to need a virtual private server for this one.

If you got that set up you can take a look at socket.io and node.js which does exactly what you're looking for. There are a couple of examples of how to set it up on their websites plus you can take a look at this blog post which has some examples on how to set up node.js and socket.io with html5's canvas and websockets to have some realtime drawing going on.


Edit: Theres a second option of running a php based socket server, although not as good as the option above, but it can probably(?) be done without vps.

PHP has seme basic functions to create a socket server that are listed here. There are a couple of examples of how to set it up such this. And theres also this stackoverflow answer here that lists a couple of google code projects that does exactly what you need such as this.

Community
  • 1
  • 1
Edward A
  • 2,291
  • 2
  • 18
  • 31
  • VPS unfortunately costs more that the shared hosting plan I have already bought. Let me see if it can be mortised to compensate for VPS pricing . – Neil Jan 25 '13 at 09:14
  • There are companies offering cheap VPS's out there (about $10 per month for some). Might be worth looking at. – webnoob Jan 25 '13 at 09:18
  • @NeilGhosh Added a VPS-less option for you. – Edward A Jan 25 '13 at 09:39
1

The best PHP WebSocket self-hosted/install solution right now is Ratchet.

However, as stated by @HartleySan, you're unlikely to be allowed to use a WebSocket solution on a shared plan due to the requirement for persistent connections. This is especially the case with general PHP solutions that allocate a large amount of resource to each request. Ratchet may have worked around this, I don't know.

IMHO the best solution for PHP is to use a hosted service such as Pusher, who I work for. There are other realtime web hosted solutions available too. This means you offload the persistent connections to the hosted service and can use your PHP stack in the normal way.

Also related: OpenShift, a PaaS, have written an article which covers the challenges of WebSockets. This helps explain the problems that other hosting providers are having when supporting WebSockets.

OpenShift do have WebSocket support in preview so you could try them out. But that is obviously a problem if you've already paid for your shared hosting. As above, I'd recommend a hosted service as the best solution.

leggetter
  • 15,248
  • 1
  • 55
  • 61