PHPackages                             upscale/swoole-reflection - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. upscale/swoole-reflection

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

upscale/swoole-reflection
=========================

Reflection API for Swoole web-server

3.2.0(1y ago)2136.7k↓48.9%3[1 PRs](https://github.com/upscalesoftware/swoole-reflection/pulls)6Apache-2.0PHPPHP &gt;=8.0CI failing

Since Mar 17Pushed 1y ago2 watchersCompare

[ Source](https://github.com/upscalesoftware/swoole-reflection)[ Packagist](https://packagist.org/packages/upscale/swoole-reflection)[ Docs](https://github.com/upscalesoftware/swoole-reflection)[ RSS](/packages/upscale-swoole-reflection/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (4)Versions (14)Used By (6)

Swoole Reflection API [![Build Status](https://github.com/upscalesoftware/swoole-reflection/workflows/Tests/badge.svg?branch=master)](https://github.com/upscalesoftware/swoole-reflection/actions?query=workflow%3ATests+branch%3Amaster)
==========================================================================================================================================================================================================================================

[](#swoole-reflection-api-)

This library provides a [Reflection API](http://us3.php.net/manual/en/intro.reflection.php) for classes of [Swoole](https://github.com/swoole/swoole-src) / [Open Swoole](https://github.com/openswoole/swoole-src) web-server.

**Features:**

- Server middleware manipulation
- Response lifecycle tracking

Installation
------------

[](#installation)

The library is to be installed via [Composer](https://getcomposer.org/) as a dependency:

```
composer require upscale/swoole-reflection
```

Usage
-----

[](#usage)

### Middleware Manipulation

[](#middleware-manipulation)

Override server middleware optionally reusing the original callback:

```
$server = new \Swoole\Http\Server('127.0.0.1', 8080);
$server->on('request', function ($request, $response) {
   $response->end("Served by Swoole server\n");
});

$reflection = new \Upscale\Swoole\Reflection\Http\Server($server);
$middleware = $reflection->getMiddleware();
$reflection->setMiddleware(function ($request, $response) use ($middleware) {
   $response->header('Content-Type', 'text/plain');
   $middleware($request, $response);
});

$server->start();
```

### Response Lifecycle

[](#response-lifecycle)

#### Headers Tracking

[](#headers-tracking)

Modify response headers before they have been sent:

```
$server->on('request', function ($request, $response) {
    $callback = function () use ($request, $response) {
        $response->header('Content-Type', 'text/plain');
    };
    $response = new \Upscale\Swoole\Reflection\Http\Response\Observable($response);
    $response->onHeadersSentBefore($callback);
    $response->end("Served by Swoole server\n");
});
```

Callback is invoked on every request upon the first call to `\Swoole\Http\Response::write/end/sendfile()`.

**Warning!** Callbacks that need to modify response must use the original response rather than its observable proxy. Dependency on observable proxy creates circular reference between the proxy and callbacks registered within it. Instances involved in orphan circular cross-references will not be destroyed until the next garbage collection cycle. Swoole calls `\Swoole\Http\Response::end()` in the response destructor executed upon the request completion. The response destructor will not be called causing the the worker to hang up without sending the response.

#### Body Interception

[](#body-interception)

Modify response body before sending it out:

```
$server->on('request', function ($request, $response) use ($server) {
    $response = new \Upscale\Swoole\Reflection\Http\Response\Observable($response);
    $response->onBodyAppend(function (&$content) use ($server) {
        $content .= "\n";
    });
    $response->header('Content-Type', 'text/html');
    $response->end("Served by Swoole server\n");
});
```

Callback is invoked on every call to `\Swoole\Http\Response::write/end()` with non-empty contents.

Contributing
------------

[](#contributing)

Pull Requests with fixes and improvements are welcome!

License
-------

[](#license)

Copyright © Upscale Software. All rights reserved.

Licensed under the [Apache License, Version 2.0](https://github.com/upscalesoftware/swoole-reflection/blob/master/LICENSE.txt).

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance42

Moderate activity, may be stable

Popularity36

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 96.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~179 days

Recently: every ~381 days

Total

13

Last Release

485d ago

Major Versions

1.4.0 → 2.0.02022-11-23

2.0.0 → 3.0.02022-11-23

PHP version history (6 changes)1.0.0PHP &gt;=5.3

1.2.0PHP &gt;=5.4

1.3.2PHP &gt;=5.5

1.3.4PHP &gt;=5.6

1.4.0PHP &gt;=7.1

2.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6521759?v=4)[Upscale Software](/maintainers/upscalesoftware)[@upscalesoftware](https://github.com/upscalesoftware)

---

Top Contributors

[![sshymko](https://avatars.githubusercontent.com/u/1231423?v=4)](https://github.com/sshymko "sshymko (61 commits)")[![geneccx](https://avatars.githubusercontent.com/u/1152573?v=4)](https://github.com/geneccx "geneccx (1 commits)")[![Rastusik](https://avatars.githubusercontent.com/u/1735097?v=4)](https://github.com/Rastusik "Rastusik (1 commits)")

---

Tags

eventmiddlewarereflectionheadersobserverswoolesubscriptionbody

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/upscale-swoole-reflection/health.svg)

```
[![Health](https://phpackages.com/badges/upscale-swoole-reflection/health.svg)](https://phpackages.com/packages/upscale-swoole-reflection)
```

###  Alternatives

[codefog/contao-events_subscriptions

events\_subscriptions extension for Contao Open Source CMS

142.7k](/packages/codefog-contao-events-subscriptions)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
