Search code examples
phpwebsocketreal-timegoogle-cloud-functionsphpwebsocket

Run PHP Web Socket on Google Cloud Virtual Machine


I created Google Cloud Virtual Machine instance with bitnami LAMP to launch PHP, MySQL and apache.

  • I've allowed firewall on port 8086 in Google Cloud Platform.

I created two files:

  1. server.php, which is

    • stored in google cloud
    • create server socket on port 8086
    • run using SSH with PHP-CLI
    • socket is binding and listening to port 8086 successfully
  2. client.php, which is

    • stored in my local PC
    • try to connect to IP and PORT(8086) of Google Cloud Instance.

Now problem is, when client.php is trying to connect to server socket on port 8086, it took too long time and then shows error saying that : Connection Timed Out

  1. Any reference regarding web socket communication on google cloud platform ?
  2. Is there any other cost efficient way to do real-time communnication ?
  3. Or should I have to try another VPS like Digital Ocean ?

Solution

  • Had almost the exact same issue, but with node.

    You should allow the port in the firewall on Google Cloud and in the Virtual machine too to get this to work.

    In Google Cloud you should open it like this answer: How to open a specific port such as 9090 in Google Compute Engine

    If you have ubuntu in your VM, you open the port typing: sudo ufw enable // This allows firewall sudo ufw allow 8086 // This allows your port

    Hope it helps.