Skip to content

Remove adapter connection mem - #30

Merged
abnegate merged 3 commits into
mainfrom
remove-adapter-connection-mem
Aug 28, 2026
Merged

Remove adapter connection mem#30
abnegate merged 3 commits into
mainfrom
remove-adapter-connection-mem

Conversation

@ArnabChatterjee20k

@ArnabChatterjee20k ArnabChatterjee20k commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Problem

The connection fd (connection id) was being stored in two layers at once:

  • Transport library (this repo) — the Swoole adapter kept a private self::$connections map (fd => true), written on open and cleared on close, exposed through getConnections().
  • Calling layer (e.g. appwrite's Realtime adapter) — keeps its own $connections map keyed by the same fd, holding the real per-connection state (projectId, roles, channels, authorization, presences, …).

Both maps maintain the same keyset of live fds. The library's copy is pure duplication: it stores nothing the caller doesn't already have, and consumers that own a richer connection registry (appwrite doesn't call getConnections() at all) end up tracking every fd twice.

Notably, the Workerman adapter never had this problem — its getConnections() read Workerman's own TcpConnection::$connections registry rather than maintaining a private mirror. Only Swoole duplicated the bookkeeping.

Change

Tracking the set of live connections belongs to the calling layer, not a generic transport library. This PR removes that responsibility from the library entirely:

  • Remove getConnections() from Adapter, Server, Swoole, and Workerman.
  • Remove the Swoole adapter's private self::$connections mirror and the onOpen/onClose bookkeeping that maintained it.
  • Update the test server stubs to keep their own $connections set (populated in onOpen/onClose) for broadcast and the /info count — demonstrating the intended pattern: the consumer owns the registry.

Impact

  • appwrite: no breakage — it never called getConnections() and already maintains its own connection map.
  • Breaking change for any other consumer relying on Server::getConnections(); such callers must track connections themselves via the onOpen/onClose callbacks. Warrants a version bump when tagged.

ArnabChatterjee20k and others added 3 commits August 28, 2026 13:19
Drop getConnections() from Adapter, Server, Swoole, and Workerman, and
remove Swoole's private self::$connections mirror. Tracking the set of
live fds belongs to the calling layer, not the transport library.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01245mLhHWfmjZejiua8wvMP
The test servers now maintain their own $connections set in onOpen/onClose
and use it for broadcast and the /info count, replacing the removed
$server->getConnections().

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01245mLhHWfmjZejiua8wvMP
phpstan (level max) flagged the $server use as unused after the /info
count switched from $server->getConnections() to the local $connections set.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01245mLhHWfmjZejiua8wvMP
@greptile-apps

greptile-apps Bot commented Aug 28, 2026

Copy link
Copy Markdown

Greptile Summary

The PR removes duplicated connection tracking and the getConnections() API from the transport abstraction, its adapters, and the server facade.

  • Removes Swoole’s private live-connection map and associated lifecycle bookkeeping.
  • Removes the Workerman and server-level connection enumeration methods.
  • Updates both test servers to own their connection registries for broadcasting and connection counts.

Confidence Score: 5/5

The PR appears safe to merge because no blocking failure remains.

No blocking failure remains.

Important Files Changed

Filename Overview
src/WebSocket/Adapter.php Removes connection enumeration from the common adapter contract.
src/WebSocket/Adapter/Swoole.php Removes the duplicated static connection registry and its open/close bookkeeping.
src/WebSocket/Adapter/Workerman.php Removes the adapter method exposing Workerman’s native connection registry.
src/WebSocket/Server.php Removes the public facade method that delegated connection enumeration to adapters.
tests/servers/Swoole/server.php Moves broadcast and connection-count tracking into the test consumer’s lifecycle callbacks.
tests/servers/Workerman/server.php Moves broadcast and connection-count tracking into the test consumer’s lifecycle callbacks.

Reviews (2): Last reviewed commit: "test: drop unused $server from onRequest..." | Re-trigger Greptile

@abnegate
abnegate merged commit 291980b into main Aug 28, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants