Commit 0e92bd0
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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
| 21 | + | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments