Repository navigation
chore: absorb websocket into packages/websocket - #13870
Conversation
Init Commit
feat: add onRequest method to WebSocket adapters
The SWOOLE_WEBSOCKET_FLAG_COMPRESS flag was hardcoded in send(), which could cause issues with Swoole 6.1.6 when clients don't support permessage-deflate compression. Now the COMPRESS flag is only included when websocket_compression is explicitly enabled in the server config. Co-Authored-By: Claude Opus 4.5 <[email protected]>
fix: only use COMPRESS flag when compression is enabled
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 <[email protected]> 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 <[email protected]> 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 <[email protected]> Claude-Session: https://claude.ai/code/session_01245mLhHWfmjZejiua8wvMP
Remove adapter connection mem
chore(websocket): absorb utopia-php/websocket
fix(websocket): time out stalled sends and reset failed connections
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
| // Use reflection to set the private properties | ||
| $reflectionClass = new \ReflectionClass(Client::class); | ||
|
|
||
| $connectedProperty = $reflectionClass->getProperty('connected'); | ||
| $connectedProperty->setValue($this->client, true); | ||
|
|
||
| $clientProperty = $reflectionClass->getProperty('client'); |
There was a problem hiding this comment.
These tests use reflection to replace Client's private connected and client properties. This violates the repository directive to never use reflection to reach private members and couples the tests to implementation details rather than observable behavior. The same pattern appears again at lines 143–149. Replace both cases with public API behavior or an explicit test seam before merging.
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/websocket/tests/ClientTest.php
Line: 104-110
Comment:
**Tests Reach Private State**
These tests use reflection to replace `Client`'s private `connected` and `client` properties. This violates the repository directive to never use reflection to reach private members and couples the tests to implementation details rather than observable behavior. The same pattern appears again at lines 143–149. Replace both cases with public API behavior or an explicit test seam before merging.
**Context Used:** AGENTS.md ([source](https://github.com/appwrite/appwrite/blob/main/AGENTS.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| $server->onClose(function (int $connection) { | ||
| echo "Connection {$workerId} closed!"; | ||
| }); |
There was a problem hiding this comment.
Close Example Uses Undefined Variable
The close callback receives $connection but interpolates $workerId, which is undefined in this scope. Users copying the example will get an undefined-variable warning and will not see the closed connection's identifier.
| $server->onClose(function (int $connection) { | |
| echo "Connection {$workerId} closed!"; | |
| }); | |
| $server->onClose(function (int $connection) { | |
| echo "Connection {$connection} closed!"; | |
| }); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/websocket/README.md
Line: 45-47
Comment:
**Close Example Uses Undefined Variable**
The close callback receives `$connection` but interpolates `$workerId`, which is undefined in this scope. Users copying the example will get an undefined-variable warning and will not see the closed connection's identifier.
```suggestion
$server->onClose(function (int $connection) {
echo "Connection {$connection} closed!";
});
```
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
|
Split run pushed |
|
Retired from the monorepo in utopia-php/monorepo#344. Its Split run no longer includes |
Summary
This moves
utopia-php/websocketintopackages/websocket, so Appwrite loads it directly. It follows the playbook inrfc/monorepo.mdand comes in three commits:Add 'packages/websocket/' from commit 'd5763527…': subtree import from the mirror with full history. The mirror head is the2.0.2tag Appwrite already pins, and its tree matchespackages/websocketinutopia-php/monorepo(f25d177), so realtime runs the same code.chore(websocket): mirror plumbing:mirror.ymlnow points here, the README banner is refreshed, and the bannedpsalm.xmlis removed.refactor: load websocket from packages/:replaceentries, drops theutopia-php/websocket: 2.0.2require line, and removes the package from the lock.src/WebSocket/*moves up tosrc/.tests/Unit/ClientTest.phpmoves up totests/.tests/E2Eandtests/Fixturesstay.tests/E2E/AdapterTest.phpdeclaredUtopia\WebSocket\Tests, which doesn't match its path, so it becomesUtopia\WebSocket\Tests\E2E.phpunit.xmlnow runstestswithtests/E2Eexcluded for the unit suite.phpstan.neonat level max oversrcandtests, with aphpstan-baseline.neonof 22 findings. The monorepo analysed this package at level 5. They aremixedhandling inClientand the Workerman adapter, plus the Swoole fixture server and e2e helpers. The RFC's phase 8 burn-down list now includes them.There's nothing to hoist, since the package requires only PHP. Its
require-dev(swoole/ide-helper,workerman/workerman) is only used by its own test tier. Appwrite uses it inapp/realtime.php,src/Appwrite/Utopia/WebSocket/Adapter/Swoole.php(which subclasses the Swoole adapter) andsrc/Appwrite/Realtime/EventTailRegistry.php, and root PHPStan passes on all of them.Open PRs, triaged
All three targeted
Adapter/Swoole.phpand are closed with a pointer here:2.0.2, which fixes the same stalled-client problem with a per-waitsendTimeoutand a connection reset. The part neither ships is a cap on pending bytes; if we want it, it can be a follow-up onpackages/websocketbuilt onsendTimeout.onMessage, which would also silently drop legitimate empty messages. Closed without porting.Validation
bin/monorepo validate: all packages validbin/monorepo check websocket: Pint and PHPStan level max (with baseline) passbin/monorepo test websocket: unit 9 tests / 22 assertions; e2e 5 tests / 996 assertions against real Swoole and Workerman fixture servers (tests/e2e.sh)vendor/bin/phpunit --testsuite packages --filter 'Utopia\\WebSocket\\Tests': 9 tests pass under the root autoloader, with E2E excludedvendor/bin/phpunit tests/unit/Realtime: 25 tests passbin/monorepo split websocket --dry-run:bed15def, which fast-forwards from the mirror headd5763527git diff --checkMerge and follow-up
Merge with a merge commit.
The
utopia-php/websocketmirror already has the canonicalmainruleset (id22146697), with the split app as an always-bypass actor, so the absorb ran with--skip-ruleset.After merge: confirm
Splitpushes toutopia-php/websocket. Then removepackages/websocketfromutopia-php/monorepo.🤖 Generated with Claude Code