Skip to content

Commit 0e92bd0

Browse files
committed
refactor(clickhouse): migrate HTTP transport from utopia-php/fetch to utopia-php/client
The old transport (utopia-php/fetch) does curl_init() → curl_exec() → curl_close() per call. The handle's connection cache is destroyed with it, so every query opens a brand-new TCP+TLS socket — keep-alive headers are advertised but never honored. Under bursty load this exhausts ephemeral ports on the calling pod with TIME_WAIT entries (tcp_fin_timeout=60s), and the kernel queues additional connect() calls until ports free. Migrate to utopia-php/client, a PSR-18 client that supports persistent connection pooling via withConnectionReuse(). The cURL handle now survives across requests — the TCP/TLS handshake is paid once per adapter, every subsequent query reuses the warm socket. Changes: - Constructor: build a single Client((new CurlAdapter()) ->withConnectionReuse()) with the auth headers and 30s timeout applied via the immutable with* builder pattern. - query() and insert(): build PSR-7 Requests via the factory (RequestFactory::form() for SELECT, RequestFactory::body() for the ndjson INSERT body) and dispatch via $client->sendRequest(). No more per-call addHeader/removeHeader mutations on a shared client. - setTimeout() now does an immutable rebuild ($client = $client ->withTimeout(seconds)). - setKeepAlive() preserved as a no-op for source-compat — connection reuse is now an adapter-level property, not a per-request header. Callers that previously passed false to "disable" reuse will see reuse enabled regardless; this is the intended behavior and the reason the migration is worth doing. PHP requirement bumps to >=8.4 to match utopia-php/client. phpstan/phpstan bumped to ^2.0 to handle PHP 8.4 syntax in utopia-php/client (chained method-on-new-expression). 96 pre-existing errors flagged by PHPStan 2.x are grandfathered via a generated baseline so this PR doesn't conflate I/O migration with a typing sweep. Refs: appwrite-labs/cloud#4453 — companion stop-gap that disables keep-alive on the cloud side. Once this lands and propagates, that workaround becomes unnecessary because the underlying socket pool now actually works.
1 parent c5c721d commit 0e92bd0

5 files changed

Lines changed: 452 additions & 118 deletions

File tree

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@
1212
"scripts": {
1313
"lint": "./vendor/bin/pint --test",
1414
"format": "./vendor/bin/pint",
15-
"check": "./vendor/bin/phpstan analyse --level max src tests",
15+
"check": "./vendor/bin/phpstan analyse -c phpstan.neon",
1616
"test": "./vendor/bin/phpunit --configuration phpunit.xml --testsuite \"Test Suite\"",
1717
"bench": "./vendor/bin/phpunit --configuration phpunit.xml --testsuite Benchmark"
1818
},
1919
"minimum-stability": "stable",
2020
"require": {
21-
"php": ">=8.0",
22-
"utopia-php/fetch": "^1.1",
21+
"php": ">=8.4",
22+
"utopia-php/client": "^0.1",
2323
"utopia-php/database": "5.*|6.0.*",
2424
"utopia-php/query": "0.1.*"
2525
},
2626
"require-dev": {
2727
"phpunit/phpunit": "^9.5",
2828
"utopia-php/cache": "^3.0",
29-
"phpstan/phpstan": "1.*",
29+
"phpstan/phpstan": "^2.0",
3030
"laravel/pint": "1.*"
3131
},
3232
"autoload": {

composer.lock

Lines changed: 114 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)