3

Let me clarify

I played with phpwebsockets and see that it requires a websocket server to run forever/constantly to keep the states etc in the memory is there any way to run websockets when there is no way of running a server on the server side?

  • i guess there is no way but it would be awesome if there is some workaround –  Jun 16 '12 at 22:00
  • Do you mean http://stackoverflow.com/questions/4277351/can-html5-websockets-connect-2-clients-browsers-directly-without-using-a-serve? – pimvdb Jun 16 '12 at 22:02
  • no not p2p i am looking for client and server such that there need not be a php script constantly running on the server side ( meaning no php server script running constantly/forever) –  Jun 16 '12 at 22:12
  • Node.JS might be what you're looking for: http://nodejs.org/ – Bailey Parker Jun 16 '12 at 22:16
  • 1
    Node.js websocket servers are still a server running constantly. – Ghedipunk Jul 07 '15 at 17:25

2 Answers2

1

You can used a hosted realtime service, such as Pusher who I work for. Here's comprehensive list of realtime hosted services.

leggetter
  • 15,248
  • 1
  • 55
  • 61
0

There will always have to be a server of some sort listening constantly. For example, HTTP traffic is delivered by a web server (Apache, Nginx, Lighttpd, etc.) that is running constantly.

It is possible for a web server to spawn a new PHP based process, then hand the client's connection over to the new process. However, none of the major web servers currently do this, and the paradigm for web server modules that route WebSocket traffic is to send the connection over to an existing, constantly running server.

You would have to write your own custom web server in order to keep from running a WebSocket server constantly... and then, really, what's the point, since you're still writing your own constantly running server?

Ghedipunk
  • 1,229
  • 10
  • 22
  • WebSockets could be used in PHP to exchange data back and forth as part of a request. Maybe there are messages that need to be exchanged in quick succession or you might want to display the progress of something without having to poll the server. There are use cases in which WebSockets in PHP are useful. And there is definitely a point in not having it constantly running. The WebSocket connection might only be kept up for a few minutes and then closed down – after which the script would simply terminate. – Simao Gomes Viana Jun 28 '23 at 14:24