Skip to content

Upgrade to utopia-php/http 2.0 and platform 1.0#5

Merged
lohanidamodar merged 1 commit into
mainfrom
chore/upgrade-http2-platform1
Jun 25, 2026
Merged

Upgrade to utopia-php/http 2.0 and platform 1.0#5
lohanidamodar merged 1 commit into
mainfrom
chore/upgrade-http2-platform1

Conversation

@lohanidamodar

Copy link
Copy Markdown
Member

What

Upgrades the geo server to the same Utopia HTTP stack used by Appwrite main and Cloud.

Dependencies

  • utopia-php/http 0.34.*^2.0@RC
  • utopia-php/platform 0.10.*^1.0@RC
  • utopia-php/cli 0.23.*^0.24 (required by platform 1.0)
  • utopia-php/di stays 0.3.* (now resolves 0.3.4)

Code

  • Resources (geodb, logger, log) are now wired through a utopia-php/di Container instead of Http::setResource(), which was removed in http 2.0.
  • The server runs on the Swoole adapter with enable_coroutine enabled, so each request is handled in its own coroutine.
  • Init action reads the auth header via Request::getHeaderLine()getHeader() now returns an array in http 2.0.
  • Removed the redundant Response::end() after Response::json(); json() already sends and ends the response (the extra end() triggered Swoole "response is unavailable" warnings).
  • Platform\Geo now initialises through the parent Platform constructor.

Testing

  • composer lint (pint) and composer check (phpstan level 8) pass.
  • Built the Docker image and booted the container:
    • GET /v1/health{"status":"ok"}
    • GET /v1/ips/:ip without a key → 401
    • GET /v1/ips/8.8.8.8 / 1.1.1.1 with key → correct country/continent payload
    • No PHP warnings or notices in the container logs.

- 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-apps

greptile-apps Bot commented Jun 25, 2026

Copy link
Copy Markdown

Greptile Summary

This PR migrates the geo server from utopia-php/http 0.34 and utopia-php/platform 0.10 to their 2.0/1.0 RC releases, aligning it with the stack used by Appwrite main and Cloud. The changes are a clean, targeted migration with no functional logic changes.

  • Resources (geodb, logger, log) are moved from Http::setResource() — removed in http 2.0 — to a utopia-php/di Container instance that is passed directly into SwooleServer; Swoole coroutines are explicitly enabled via enable_coroutine: true.
  • Auth header reading in Init is corrected from getHeader() (now returns array in http 2.0) to getHeaderLine() (returns string); Response::end() is removed from Get and Health since json() already ends the response in http 2.0.
  • Platform\\Geo is updated to initialise through the parent Platform constructor as required by platform 1.0.

Confidence Score: 4/5

Safe 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

Filename Overview
src/Geo/Server/Server.php Core refactoring — resources migrated from Http::setResource() to a DI Container passed into SwooleServer; worth verifying whether Container::set() creates per-resolution instances or singletons for the mutable Log resource
src/Geo/Modules/Core/Http/Init.php Correct migration from getHeader() (returns array in http 2.0) to getHeaderLine() (returns string); auth logic unchanged
src/Geo/Platform/Geo.php Correctly switches from addModule() to parent::__construct(new Core()) as required by platform 1.0 API
composer.json Version bumps to http ^2.0@RC and platform ^1.0@RC (Release Candidates); intentional alignment with Appwrite main/Cloud
composer.lock Generated lockfile updated to match new deps; several packages removed (php-amqplib, phpseclib, paragonie) as they were pulled in by the old platform/queue chain

Reviews (1): Last reviewed commit: "Upgrade to utopia-php/http 2.0 and platf..." | Re-trigger Greptile

Comment thread src/Geo/Server/Server.php
});

$this->http->setResource('log', fn () => new Log());
$this->resources->set('log', fn () => new Log());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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!

@lohanidamodar lohanidamodar merged commit 5143164 into main Jun 25, 2026
4 checks passed
@lohanidamodar lohanidamodar deleted the chore/upgrade-http2-platform1 branch June 25, 2026 06:37
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.

1 participant