PHP Websocket server in Linux hosting

12,973

Solution 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.

Solution 2

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.

Solution 3

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.

Share:
12,973
Neil
Author by

Neil

Updated on June 16, 2022

Comments

  • Neil
    Neil about 2 years

    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
    Neil over 11 years
    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
    Neil over 11 years
    So in shared hosting only port 80 is available ?
  • webnoob
    webnoob over 11 years
    That is a question which would be better suited for GoDaddy support.
  • webnoob
    webnoob over 11 years
    There are companies offering cheap VPS's out there (about $10 per month for some). Might be worth looking at.
  • Edward A
    Edward A over 11 years
    @NeilGhosh Added a VPS-less option for you.
  • Anoop saju
    Anoop saju about 8 years
    WebSockets by default will work fine only with Node.js and DIY cartridges in case of Openshift