Download the PHP package axcherednikov/php-websocket without Composer

On this page you can find all versions of the php package axcherednikov/php-websocket. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-websocket

ext-websocket

Native WebSocket extension for PHP.

ext-websocket keeps RFC 6455 protocol work in C and exposes a small PHP API for synchronous PHP code, async runtimes, and the native server runtime included in the extension.

Requirements

Installation

Via PIE

From Source

Enable the extension:

Check that PHP can load it:

With Homebrew PHP:

Quick Start

See examples/run_server.php for a runnable example.

Protocol Helpers

Public API

WebSocket\Server

Options:

Option Description
maxMessageSize Maximum incoming text/binary message size; defaults to 16 MiB
maxQueuedBytes Maximum outgoing queued bytes per connection; defaults to 16 MiB
maxConnections Maximum concurrently accepted TCP connections; defaults to 10000
handshakeTimeoutMs Maximum idle time before HTTP Upgrade completes; defaults to 10000 ms
idleTimeoutMs Maximum idle time after HTTP Upgrade completes; defaults to 120000 ms
pingIntervalMs Idle time before sending an automatic ping; 0 disables heartbeat pings by default
pongTimeoutMs Maximum time to wait for a pong after an automatic ping; defaults to 10000 ms

Prefer WebSocket\ServerOptions for explicit configuration. Associative arrays remain supported for compatibility.

Methods:

Method Description
__construct(ServerOptions\|array $options = []) Create a server
listen(string $host, int $port): void Bind address for run()
subprotocols(string ...$protocols): void Configure supported Sec-WebSocket-Protocol tokens
onHandshake(Closure $handler): void Accept or reject valid HTTP Upgrade requests before 101 Switching Protocols
onOpen(Closure $handler): void Register upgraded connection callback
onMessage(Closure $handler): void Register text/binary message callback
onClose(Closure $handler): void Register close callback
onError(Closure $handler): void Register runtime error callback
run(): void Start accept, HTTP Upgrade, and frame processing loop
stop(): void Request shutdown
getDriver(): string Return selected I/O driver

Handshake callbacks receive a WebSocket\Request. Return normally to continue the WebSocket upgrade, or throw WebSocket\HandshakeException to reject it before 101 Switching Protocols is sent:

WebSocket\Request

Method / property Description
header(string $name): ?string Return a case-insensitive request header value
readonly string $method HTTP request method
readonly string $target HTTP request target
readonly array $headers Lower-case request headers

WebSocket\HandshakeResponse

Method / property Description
__construct(int $status = 403, array $headers = [], string $body = '') Create a custom handshake rejection response
readonly int $status HTTP status code
readonly array $headers HTTP response headers
readonly string $body HTTP response body

WebSocket\HandshakeException

Method / property Description
__construct(?HandshakeResponse $response = null) Create a handshake rejection exception; defaults to 403 Forbidden
readonly HandshakeResponse $response HTTP response sent before closing the connection

WebSocket\Connection

Method / property Description
send(string $payload, MessageType $type = MessageType::Text): void Send text, binary, or control payload
close(int $code = 1000, string $reason = ''): void Send close frame and close the connection
isOpen(): bool Check connection state
readonly string $id Connection id
readonly string $remoteAddress Remote peer address
readonly ?string $subprotocol Negotiated subprotocol, or null

WebSocket\Protocol

Method Description
acceptKey(string $key): string Build Sec-WebSocket-Accept
encode(string $payload, MessageType $type = MessageType::Text, bool $masked = false): string Encode one frame
decode(string $buffer): Frame\|CloseFrame\|null Decode one frame
pack(string\|Frame\|CloseFrame $data, int $opcode = Protocol::OPCODE_TEXT, int $flags = Protocol::FLAG_FIN): string Encode with raw opcode and flags
unpack(string $buffer): Frame\|CloseFrame\|null Decode with raw opcode and flags

Value Objects

Class Description
Frame Non-close WebSocket frame with type, opcode, flags, payload, final, and bytesConsumed
CloseFrame Close frame with code, reason, flags, and bytesConsumed
MessageType Enum cases: Continuation, Text, Binary, Ping, Pong, Close

Benchmarks

Detailed benchmark results and commands live in the separate php-websocket-bench repository.

The benchmark suite covers protocol encode/decode, server upgrade runtime, and real ws:// / wss:// message runtime against AMPHP, Workerman, OpenSwoole, and Ratchet.

Production

See docs/production.md for deployment notes and current runtime limits.

IDE Support

Use websocket.stub.php as an IDE/static-analysis stub for PhpStorm, PHPStan, Psalm, or similar tools.

Testing

To run tests against the built module directly:

Changelog

See CHANGELOG.md.

License

MIT. See LICENSE.


All versions of php-websocket with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package axcherednikov/php-websocket contains the following files

Loading the files please wait ...