Download the PHP package dimogrudev/php-websocket without Composer
On this page you can find all versions of the php package dimogrudev/php-websocket. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dimogrudev/php-websocket
More information about dimogrudev/php-websocket
Files in dimogrudev/php-websocket
Package php-websocket
Short Description No-dependency implementation of WebSocket server in PHP
License MIT
Informations about the package php-websocket
PHP WebSocket Server
A zero-dependency native implementation of WebSocket server in PHP.
Lightweight and minimalistic.
Features
- Strict adherence to RFC 6455
- Automatic HTTP Upgrade handshake compliant with RFC 9110 and RFC 9112
- SSL/TLS encryption support
- Binary and textual data message support, both sending and receiving
- Transparent reassembly of incoming fragmented messages
- Built-in handling for Ping, Pong, and Close control frames
- Non-blocking UDP datagram networking
- User-defined non-blocking timers
- Non-blocking I/O
Requirements
- PHP 8.4 or higher (64-bit)
[!IMPORTANT] If you plan to run websockets on a shared hosting, note that most providers block ports for any third-party usage. A VPS or dedicated server is highly recommended.
Installation
This library may be installed via Composer:
Usage
[!TIP] Modern browsers block non-secure WebSocket connections (
ws://) on secure websites (https://). For production, always use a valid SSL/TLS certificate (e.g., Let's Encrypt) or run the server behind a secure reverse proxy (like Nginx, Caddy, or Traefik) to handle SSL/TLS termination.
UDP Networking
Timers
Callbacks Reference
| Method | Signature | Description |
|---|---|---|
onServerStart |
(): void |
Triggered when the server starts listening. |
onServerStop |
(): void |
Triggered when the server stops. |
onHandshake |
(ClientInterface, RequestInterface): bool |
Triggered when a handshake request is received. Return true to accept the connection. |
onClientConnect |
(ClientInterface): void |
Triggered after the handshake is accepted and the connection is fully established. |
onClientDisconnect |
(ClientInterface): void |
Triggered when the connection is closed. |
onMessageReceive |
(ClientInterface, MessageInterface): void |
Triggered when a complete data message is received. |
Connection Security
Unauthorized connections may be rejected by using the onHandshake callback:
License
The MIT License (MIT). For more information, please see LICENSE.