Skip to content

chore: experiments#253

Open
loks0n wants to merge 1 commit intomainfrom
chore/experiments
Open

chore: experiments#253
loks0n wants to merge 1 commit intomainfrom
chore/experiments

Conversation

@loks0n
Copy link
Copy Markdown
Contributor

@loks0n loks0n commented May 5, 2026

No description provided.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 5, 2026

Greptile Summary

This PR consolidates the Swoole adapters into two new classes (Swoole and SwooleCoroutine), introduces a Mode enum with opinionated server tuning, a cgroup-aware System::getCpuNum() helper, and a Compression value object — all solid additions. However, several critical bugs in the in-progress refactor of Http.php and Response.php will prevent the application from booting or compressing responses.

  • P0protected static array $ = []; in Http.php is a PHP syntax error (property name missing); the entire app fails to parse.
  • P0$this->compression->isCompressible(self) in Response.php uses the class-reference keyword self as an object argument plus a stray ; that breaks the if condition.
  • P0$this->resources is referenced in Http::start() but no such property exists; setResource() is also called there after being deleted.

Confidence Score: 1/5

Not safe to merge — multiple P0 syntax/runtime errors will prevent the application from loading.

Three independent P0 findings each independently block the application from running: a PHP parse error on the unnamed property, a syntax error in the compression conditional, and an undefined property reference. The PR is in an intermediate experiments state and should not be merged until these are resolved.

src/Http/Http.php and src/Http/Response.php both have P0 errors that need immediate attention before this PR is mergeable.

Important Files Changed

Filename Overview
src/Http/Http.php Multiple fatal errors: unnamed property $ = [], reference to undefined $this->resources, call to removed setResource() method — application will not boot.
src/Http/Response.php Fatal syntax error in compression condition: self keyword used as object argument and stray ; breaks the if condition; compression is completely non-functional.
src/Http/Compression.php New Compression value object encapsulating configuration; minor issue with dead code ($hasAcceptEncoding unused) and misleading parameter name.
src/Http/Adapter/Swoole.php New consolidated Swoole adapter with context-aware DI via coroutine context; logic is sound.
src/Http/Adapter/Swoole/Mode.php New enum defining HYPERLOOP_A/B server modes with well-documented Swoole settings; logic is correct.
src/Http/Adapter/Swoole/System.php New helper for cgroup-aware CPU count detection; correct fall-through logic across cgroup v2/v1, macOS, /proc/cpuinfo, and Swoole.
src/Http/Adapter/SwooleCoroutine.php New coroutine HTTP server adapter; correctly uses finally to clean up context key and queues multiple onStart callbacks.
src/Http/Adapter/FPM.php Renamed and simplified FPM adapter with getContext() replacing getContainer(); straightforward refactor.
src/Http/Adapter.php Abstract method renamed from getContainer() to getContext(); small breaking API change but clean in isolation.

Comments Outside Diff (1)

  1. src/Http/Http.php, line 438 (link)

    P0 Call to removed method setResource

    $this->setResource(...) is invoked in the onStart error handler, but the setResource public method was deleted in this PR. This will throw a fatal Call to undefined method error whenever a start-hook throws an exception.

Reviews (1): Last reviewed commit: "chore: experiments" | Re-trigger Greptile

Comment thread src/Http/Http.php
* @var Hook[]
*/
protected static array $startHooks = [];
protected static array $ = [];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P0 Syntax error: unnamed static property

protected static array $ = []; is not valid PHP — a property must have an identifier after $. PHP will throw a fatal parse error on this line, making the entire application unbootable. This appears to be the renamed $startHooks property (referenced on line 433 via self::$startHooks), whose name was lost during the refactor.

Comment thread src/Http/Response.php
Comment on lines 469 to 474
if (
!$hasContentEncoding
$this->compression
&& !$hasContentEncoding
&& !empty($this->acceptEncoding)
&& $this->isCompressible($this->contentType)
&& \strlen($body) > $this->compressionMinSize
&& $this->compression->isCompressible(self);
) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P0 Syntax error: self keyword and stray semicolon in condition

self is a class-reference keyword in PHP, not an expression that can be passed as a method argument — this should be $this. Additionally, the trailing semicolon ; terminates the if condition early, making the && clause a separate (unreachable) statement. Both errors will cause a fatal parse/runtime error and prevent compression from ever being applied.

Suggested change
if (
!$hasContentEncoding
$this->compression
&& !$hasContentEncoding
&& !empty($this->acceptEncoding)
&& $this->isCompressible($this->contentType)
&& \strlen($body) > $this->compressionMinSize
&& $this->compression->isCompressible(self);
) {
if (
$this->compression
&& !$hasContentEncoding
&& !empty($this->acceptEncoding)
&& $this->compression->isCompressible($this)
) {

Comment thread src/Http/Http.php

$this->server->onStart(function ($server) {
$this->setResource('server', fn() => $server);
$this->resources->set('server', fn() => $server);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P0 Undefined property $resources

The constructor no longer assigns $this->container = $server->getContext() or declares a $resources property, yet this line calls $this->resources->set(...). The class still declares protected Container $container (line 43) but it is never initialized either. This will throw an "Undefined property" or "must not be accessed before initialization" fatal error at runtime when start() is called.

Comment thread src/Http/Compression.php
Comment on lines +101 to +108
public function isCompressible(Response $request): bool
{
$hasAcceptEncoding = !empty($request->getHeader('accept-encoding', ''));

$isCompressibleMimeType = isset($this->mimeTypes[$request->getHeader('content-type', '')]);
$isGreaterThanMinSize = \strlen($request->getRawPayload()) > $this->minSizeBytes;
return $isCompressibleMimeType && $isGreaterThanMinSize;
}
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 $hasAcceptEncoding computed but never used; misleading parameter name

The variable is calculated but excluded from the return expression, so the caller's Accept-Encoding presence is silently ignored by isCompressible. The parameter is also typed as Response but named $request, which is misleading.

Suggested change
public function isCompressible(Response $request): bool
{
$hasAcceptEncoding = !empty($request->getHeader('accept-encoding', ''));
$isCompressibleMimeType = isset($this->mimeTypes[$request->getHeader('content-type', '')]);
$isGreaterThanMinSize = \strlen($request->getRawPayload()) > $this->minSizeBytes;
return $isCompressibleMimeType && $isGreaterThanMinSize;
}
public function isCompressible(Response $response): bool
{
$isCompressibleMimeType = isset($this->mimeTypes[$response->getHeader('content-type', '')]);
$isGreaterThanMinSize = \strlen($response->getRawPayload()) > $this->minSizeBytes;
return $isCompressibleMimeType && $isGreaterThanMinSize;
}

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