Upgrade to utopia-php/http 2.0 and platform 1.0#5
Conversation
- Bump utopia-php/http 0.34 -> ^2.0@RC, platform 0.10 -> ^1.0@RC, cli 0.23 -> ^0.24 - Move resource wiring to a utopia-php/di Container and run requests on the Swoole coroutine-enabled server adapter - Use Request::getHeaderLine() in the init action (getHeader now returns an array) - Drop redundant Response::end() after json() (json() already ends the response) - Initialise the platform via the parent Platform constructor
Greptile SummaryThis PR migrates the geo server from
Confidence Score: 4/5Safe to merge; all migration steps are correctly applied and manually tested. One open question about DI Container lifecycle for the mutable Log resource is worth confirming before relying on coroutine isolation. Every breaking-change point in the http 2.0/platform 1.0 migration is addressed correctly. The only uncertainty is whether Container::set() resolves factory closures on every injection (per-request) or caches after first call (singleton) — this matters for the Log resource under concurrent Swoole coroutines, but doesn't affect the geo lookup or auth logic. src/Geo/Server/Server.php — specifically the log resource registration and its lifecycle under concurrent coroutines. Important Files Changed
Reviews (1): Last reviewed commit: "Upgrade to utopia-php/http 2.0 and platf..." | Re-trigger Greptile |
| }); | ||
|
|
||
| $this->http->setResource('log', fn () => new Log()); | ||
| $this->resources->set('log', fn () => new Log()); |
There was a problem hiding this comment.
Log resource lifecycle under Swoole coroutines
The log resource is registered with Container::set() using a plain closure. If Container::set() resolves the closure once and caches the result (singleton semantics), the same Log instance will be shared across all concurrent coroutine requests — causing log context from one request to bleed into another. In the old Http::setResource() API, closures were invoked per-request to produce fresh instances. It's worth confirming that Container::set() in utopia-php/di 0.3.4 also resolves the factory closure on every injection (not just the first), given that enable_coroutine is enabled and geodb/logger are intentionally long-lived singletons while log must be per-request.
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!
What
Upgrades the geo server to the same Utopia HTTP stack used by Appwrite main and Cloud.
Dependencies
utopia-php/http0.34.*→^2.0@RCutopia-php/platform0.10.*→^1.0@RCutopia-php/cli0.23.*→^0.24(required by platform 1.0)utopia-php/distays0.3.*(now resolves 0.3.4)Code
geodb,logger,log) are now wired through autopia-php/diContainerinstead ofHttp::setResource(), which was removed in http 2.0.enable_coroutineenabled, so each request is handled in its own coroutine.Initaction reads the auth header viaRequest::getHeaderLine()—getHeader()now returns an array in http 2.0.Response::end()afterResponse::json();json()already sends and ends the response (the extraend()triggered Swoole "response is unavailable" warnings).Platform\Geonow initialises through the parentPlatformconstructor.Testing
composer lint(pint) andcomposer check(phpstan level 8) pass.GET /v1/health→{"status":"ok"}GET /v1/ips/:ipwithout a key →401GET /v1/ips/8.8.8.8/1.1.1.1with key → correct country/continent payload