PHPackages                             luisinder/remote-port-middleware - 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. luisinder/remote-port-middleware

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

luisinder/remote-port-middleware
================================

PSR-7 / PSR-15 middleware that determines the client remote TCP port and stores it as a ServerRequest attribute (remotePort). Compatible with Slim 3 (legacy) &amp; Slim 4+.

v2.0.0(1y ago)219BSD-3-ClausePHPPHP &gt;=8.0

Since Sep 28Pushed 1y ago1 watchersCompare

[ Source](https://github.com/luisinder/remote-port-middleware)[ Packagist](https://packagist.org/packages/luisinder/remote-port-middleware)[ Docs](https://github.com/lcajigasm/remote-port-middleware)[ RSS](/packages/luisinder-remote-port-middleware/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (2)Versions (4)Used By (0)

Remote Port Middleware
======================

[](#remote-port-middleware)

[![Latest Stable Version](https://camo.githubusercontent.com/3185bcca6930f488aea79ecdd80d82608a6172cbe60f98aa920c0f4940c15b68/68747470733a2f2f706f7365722e707567782e6f72672f6c756973696e6465722f72656d6f74652d706f72742d6d6964646c65776172652f762f737461626c65)](https://packagist.org/packages/luisinder/remote-port-middleware)[![Total Downloads](https://camo.githubusercontent.com/cb5fb94ef7dd9c6453bdf5e7b939998793059212e1a1d0d16dc8275936d2b625/68747470733a2f2f706f7365722e707567782e6f72672f6c756973696e6465722f72656d6f74652d706f72742d6d6964646c65776172652f646f776e6c6f616473)](https://packagist.org/packages/luisinder/remote-port-middleware)

PSR-7 / PSR-15 middleware that determines the client's remote TCP port (from the `REMOTE_PORT` server param) and stores it as a `ServerRequest` attribute named `remotePort`.

Works with:

- Slim 4+ (PSR-15 single-pass)
- Slim 3 (legacy double-pass) – still supported for backwards compatibility
- Any PSR-15 compatible framework (Mezzio, etc.)

Requirements
------------

[](#requirements)

- PHP &gt;= 8.0
- psr/http-message ^1.0 || ^2.0
- psr/http-server-middleware ^1.0

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

[](#installation)

```
composer require luisinder/remote-port-middleware
```

How it works
------------

[](#how-it-works)

On each request the middleware inspects `$request->getServerParams()['REMOTE_PORT']` (if present) and attaches it to the request as `remotePort` (integer or `null` if missing).

Usage (Slim 4+)
---------------

[](#usage-slim-4)

```
use Slim\Factory\AppFactory;
use Luisinder\Middleware\RemotePort;

require __DIR__ . '/vendor/autoload.php';

$app = AppFactory::create();
$app->add(RemotePort::class); // or new RemotePort()

$app->get('/', function ($request, $response) {
    $remotePort = $request->getAttribute('remotePort');
    $response->getBody()->write('Remote port: ' . ($remotePort ?? 'unknown'));
    return $response;
});

$app->run();
```

### Container registration (optional)

[](#container-registration-optional)

If you prefer adding via DI container (e.g. using PHP-DI):

```
$container->set(RemotePort::class, function() { return new RemotePort(); });
$app->add(RemotePort::class);
```

Usage (Slim 3 legacy)
---------------------

[](#usage-slim-3-legacy)

```
$app->add(new Luisinder\Middleware\RemotePort());

$app->get('/', function ($request, $response) {
    $remotePort = $request->getAttribute('remotePort');
    return $response->write('Remote port: ' . ($remotePort ?? 'unknown'));
});
```

Attribute name
--------------

[](#attribute-name)

The attribute key is `remotePort`. Example:

```
$remotePort = $request->getAttribute('remotePort'); // int|null
```

Error handling &amp; edge cases
-------------------------------

[](#error-handling--edge-cases)

If `REMOTE_PORT` is missing the attribute value will be `null`.

Testing
-------

[](#testing)

You can simulate a request by constructing a PSR-7 `ServerRequest` with a custom server params array:

```
$request = $request->withServerParams(['REMOTE_PORT' => 54321]);
```

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

[](#contributing)

PRs and issues are welcome. Please include tests where possible.

License
-------

[](#license)

BSD-3-Clause. See the `LICENSE` file for details.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance49

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~1619 days

Total

3

Last Release

370d ago

Major Versions

1.0.1 → v2.0.02025-08-10

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/280819769?v=4)[luisinder](/maintainers/luisinder)[@luisinder](https://github.com/luisinder)

---

Top Contributors

[![lcajigasm](https://avatars.githubusercontent.com/u/6973356?v=4)](https://github.com/lcajigasm "lcajigasm (6 commits)")

---

Tags

middlewarepsr7slimportpsr15remote port

### Embed Badge

![Health badge](/badges/luisinder-remote-port-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/luisinder-remote-port-middleware/health.svg)](https://phpackages.com/packages/luisinder-remote-port-middleware)
```

###  Alternatives

[mcp/sdk

Model Context Protocol SDK for Client and Server applications in PHP

1.6k2.2M140](/packages/mcp-sdk)[cakephp/authentication

Authentication plugin for CakePHP

1214.3M118](/packages/cakephp-authentication)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[jaxon-php/jaxon-core

Jaxon is an open source PHP library for easily creating Ajax web applications

73151.3k35](/packages/jaxon-php-jaxon-core)[flarum/core

Delightfully simple forum software.

211.5M2.5k](/packages/flarum-core)[xima/xima-typo3-frontend-edit

Frontend Edit - This extension provides an edit button for editors within frontend content elements.

1615.6k](/packages/xima-xima-typo3-frontend-edit)

PHPackages © 2026

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