GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - chapterjason/frankenphp-websocket: FrankenPHP extension in Go that gives PHP WebSocket support over HTTP/1.1, HTTP/2 and HTTP/3: the handshake is a normal PHP request, events go to a PHP worker, and PHP pushes to any connection, clustered over NATS or Unix sockets.

BranchesTags
Open more actions menu

Latest commit

 

History

1 Commit
1 Commit

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
docs
docs
 
 
e2e
e2e
 
 
internal
internal
 
 
scripts
scripts
 
 
.dockerignore
.dockerignore
 
 
.gitignore
.gitignore
 
 
.golangci.yml
.golangci.yml
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CLAUDE.md
CLAUDE.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
Dockerfile
Dockerfile
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
SECURITY.md
SECURITY.md
 
 
frankenphpwebsocket.go
frankenphpwebsocket.go
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 

Repository files navigation

FrankenPHP WebSocket

CI License: MIT

A FrankenPHP extension, written in Go, that gives PHP applications WebSocket support. Go holds the connections; PHP decides on every handshake, handles every event and pushes data to any connection, from its workers and from regular requests. Several instances can form a cluster, connected directly or through relays.

  • WebSockets over HTTP/1.1 (RFC 6455), HTTP/2 (RFC 8441) and HTTP/3 (RFC 9220)
  • The handshake reaches PHP as an ordinary HTTP request, so an application firewall applies to it as to any other request
  • permessage-deflate compression (RFC 7692), when PHP asks for it
  • Attributes and tags on connections, sends to a tag or to all connections
  • Limits on connections, message size and message rate; idle timeout and keepalive pings
  • Clusters of servers, connected directly or through relays, so any server reaches every connection
  • PHP messaging between the servers of a cluster, with or without WebSockets
  • Queue workers, schedulers and other PHP commands in the cluster, without accepting connections

How it fits together

Clients connect to a server; servers can form a cluster:

┌──────────────────┐                      ┌──────────┐                  ┌─────────────────┐
│     Clients      │  WebSocket over      │          │     cluster      │  Other servers  │
│ (browsers, apps) │═════════════════════▶│  Server  │◀════════════════▶│ (mesh, relays)  │
│                  │  HTTP/1.1, /2, /3    │          │                  │                 │
└──────────────────┘                      └──────────┘                  └─────────────────┘

Inside a server, the extension holds the clients' connections and hands their events to a PHP worker; PHP pushes back from that worker and from regular requests. As a member of a cluster, its PHP also talks to the PHP of the other members:

                       Clients (browsers, apps)
                                │
                                │ WebSocket over HTTP/1.1, HTTP/2 or HTTP/3
┌───────────────────────────────┼──── Server: Caddy + FrankenPHP + this extension ───────┐
│                               ▼                                                        │
│                 ┌───────────────────────────┐    events      ┌──────────────────────┐  │
│                 │    websocket directive    │───────────────▶│   WebSocket worker   │  │
│                 │   holds the connections   │◀───────────────│    websocket.php     │  │
│                 └─────────────┬─────────────┘   replies,     └──────────────────────┘  │
│                               │               websocket_*()                            │
│                               │                                                        │
│                               │         websocket_*()        ┌──────────────────────┐  │
│                               │◀─────────────────────────────│     PHP requests     │  │
│   connections on              │                              │      php_server      │  │
│   other servers               │                              └───────────┬──────────┘  │
│                               │                                          │             │
│                               │                                          │             │
│                               │                                          │ cluster_*() │
│                               ▼                                          │             │
│                 ┌───────────────────────────┐                            │             │
│                 │                           │◀───────────────────────────┘             │
│                 │      cluster member       │   messages     ┌──────────────────────┐  │
│                 │       mesh, uplink        │───────────────▶│    Cluster worker    │  │
│                 │                           │◀───────────────│     cluster.php      │  │
│                 └─────────────┬─────────────┘  cluster_*()   └──────────────────────┘  │
│                               │                                                        │
│                               │                                                        │
└───────────────────────────────┼────────────────────────────────────────────────────────┘
                                │ other members: connections (mesh) or tunnels (relay)
                                ▼

In a cluster, members connect directly in a mesh, or through relays when they cannot reach each other, such as behind NAT:

   Clients                 Clients                          Clients
      │                       │                                │
 ┌────▼─────┐   direct   ┌────▼─────┐                    ┌─────▼────┐
 │ Server A │◀══════════▶│ Server B │                    │ Server C │
 │ mesh     │            │ mesh     │                    │ uplink   │ behind NAT
 │ uplink   │            │ uplink   │                    └─────┬────┘
 └────┬─────┘            └────┬─────┘                          │
      │                       │         ┌────────────────┐     │
      └─────── uplink ────────┴────────▶│    Relay R     │◀────┘
                                        │ cluster relay  │
                                        │ passes tunnels │
                                        │ no clients     │
                                        └────────────────┘

   A ↔ B: direct      A ↔ C, B ↔ C: tunnels through R
Participant What it is Configured with
Client A browser or app with a WebSocket connection Clients
Server Caddy with FrankenPHP and this extension Installation
WebSocket worker PHP that decides on handshakes and handles the events of connections The WebSocket worker
PHP requests Regular PHP, which pushes with the websocket_* functions PHP functions
Member A server in a cluster, reaching the connections and the PHP of the other members Mesh Uplink
Cluster worker PHP that gets what other members send with the cluster_* functions The cluster worker
Relay Joins members that cannot reach each other and passes their tunnels through; a server can be a relay and a member at once Relay
CLI participant PHP run with frankenphp php-cli, such as a queue worker or a scheduler, that takes part like a member but accepts no connections CLI participants

Documentation

  • Installation
  • Configuration
  • Clients
  • The WebSocket worker
  • PHP functions
  • Cluster
    • Mesh
    • Uplink
    • Relay
    • The cluster worker
    • CLI participants
  • Performance
  • Known limitations
  • Development

About

FrankenPHP extension in Go that gives PHP WebSocket support over HTTP/1.1, HTTP/2 and HTTP/3: the handshake is a normal PHP request, events go to a PHP worker, and PHP pushes to any connection, clustered over NATS or Unix sockets.

Topics

caddycaddy-moduledockerfrankenphpgogolanghttp2http3natsphpphp-extensionpushquicrealtimerfc6455rfc8441rfc9220websocket

Resources

Readme
MIT license

Contributing

Contributing

Security policy

Security policy
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.