How do i setup websocket on GCP Flex environment?

247 views Asked by At

I am using laravel 6 and I want to deploy laravel based websocket server using supervisor on google cloud Flex app engine platform.

I am using this package: beyondcode/laravel-websockets

I have setup everything and everything is working fine on local machine! What is the exact procedure to follow to deploy it on GCP?

My additional-supervisord.conf

[program:websockets]
command = php %(ENV_APP_DIR)s/artisan websockets:serve
enviroment = PORT="6001"
stdout_logfile = /dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile = /dev/stderr
stderr_logfile_maxbytes=0
user = root
autostart = true
autorestart = true
priority = 10
stopwaitsecs = 20

App.yaml

runtime: php
env: flex

runtime_config:
  document_root: public

service: orders

skip_files:
  - .env

#only for testing purpose. 
manual_scaling:
  instances: 1

env_variables:
  APP_NAME: "Havn"
  BROADCAST_DRIVER: pusher
  PUSHER_APP_ID: SOMEID
  PUSHER_APP_KEY: SOMEKEY
  PUSHER_APP_SECRET: SOMESECRET
  PUSHER_APP_CLUSTER: mt1
  LARAVEL_WEBSOCKETS_PORT: 6001
  PUSHER_SCHEME: https
  PUSHER_HOST: 127.0.0.1
  PUSHER_PORT: 6001
  QUEUE_DRIVER: database

beta_settings:
  cloud_sql_instances: "INSTANCE ID"
1

There are 1 answers

0
marian.vladoi On

You can find in the official documentation how to use WebSockets to create a persistent connection from a client (such as a mobile device or a computer) to an App Engine instance.

Please consider that WebSockets connection will time out after one hour.

Creating Persistent Connections with WebSockets PHP