PHPackages                             phpsgi/funk - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. phpsgi/funk

ActiveLibrary[HTTP &amp; Networking](/categories/http)

phpsgi/funk
===========

An implementation of PHPSGI middleware specification

14950[2 issues](https://github.com/phpsgi/Funk/issues)3PHP

Since Jun 3Pushed 8y ago5 watchersCompare

[ Source](https://github.com/phpsgi/Funk)[ Packagist](https://packagist.org/packages/phpsgi/funk)[ RSS](/packages/phpsgi-funk/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (3)

Funk
====

[](#funk)

[![Build Status](https://camo.githubusercontent.com/59edc4d6280a33bddb01230be4b7824c949e748977490079396bbf5db5cf756a/68747470733a2f2f7472617669732d63692e6f72672f7068707367692f46756e6b2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phpsgi/Funk)[![Coverage Status](https://camo.githubusercontent.com/89626dc4633443cfbdfca65cfdbc6c78513facc8bce37ebdf8a36eb811d38008/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f7068707367692f46756e6b2e737667)](https://coveralls.io/r/phpsgi/Funk)[![Latest Stable Version](https://camo.githubusercontent.com/c73e5838803c734ce80f6a51122fe3c4c895b39ce7cde9aa125e4d5af83693d1/68747470733a2f2f706f7365722e707567782e6f72672f7068707367692f66756e6b2f762f737461626c652e737667)](https://packagist.org/packages/phpsgi/funk)[![Total Downloads](https://camo.githubusercontent.com/ab44f543fc3170cba9f5ebd0cfdc5c4cbb4ba84e03b7608f1dbdb813d569a95f/68747470733a2f2f706f7365722e707567782e6f72672f7068707367692f66756e6b2f646f776e6c6f6164732e737667)](https://packagist.org/packages/phpsgi/funk)[![Monthly Downloads](https://camo.githubusercontent.com/09c59711839c13ca25da51c26ab523c161ffcf8d0ac740f7a9590965c9778809/68747470733a2f2f706f7365722e707567782e6f72672f7068707367692f66756e6b2f642f6d6f6e74686c79)](https://packagist.org/packages/phpsgi/funk)[![Daily Downloads](https://camo.githubusercontent.com/7954220c091a29ce7cb372b94167313734936c6d0a66ff02d22d5f164ea39b5e/68747470733a2f2f706f7365722e707567782e6f72672f7068707367692f66756e6b2f642f6461696c79)](https://packagist.org/packages/phpsgi/funk)[![Latest Unstable Version](https://camo.githubusercontent.com/1e6a5fc955afab4060298366f437d78fa949ba0553623dff6cdb8f198b1f3d3a/68747470733a2f2f706f7365722e707567782e6f72672f7068707367692f66756e6b2f762f756e737461626c652e737667)](https://packagist.org/packages/phpsgi/funk)[![License](https://camo.githubusercontent.com/58703f56bef535f352a01bd561f8220c651f56efea5deda761ce9cb9ba4d94f1/68747470733a2f2f706f7365722e707567782e6f72672f7068707367692f66756e6b2f6c6963656e73652e737667)](https://packagist.org/packages/phpsgi/funk)[![Join the chat at https://gitter.im/phpsgi/funk](https://camo.githubusercontent.com/cc0e131ea416c7d5b3da50722b8adcb67c700b6636494d844a2d58e2f0ebe0d7/68747470733a2f2f6261646765732e6769747465722e696d2f7068707367692f66756e6b2e737667)](https://gitter.im/phpsgi/funk?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)[![Made in Taiwan](https://camo.githubusercontent.com/9ff8461912d454a52a3c2a22a80da9a976140bdb7125bb360d029ebeb755985f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d616465253230696e2d74616977616e2d677265656e2e737667)](README.md)

Funk is an implementation of PHPSGI. It supports HTTP servers implemented with PHP SAPI (Apache2 `mod_php`, `php-fpm`, `fastcgi`), therefore you can integrate your application with Funk and switch to different HTTP server implementation.

PHPSGI and Funk aims to provide lightweight HTTP interfaces, middlewares for web frameworks. It's a bit different from the PSR-7 spec. PHPSGI focuses on the core data structure instead of forcing components to implement the interface requirements.

Components
----------

[](#components)

- HTTP server (with event extension or `socket_select`)
- SAPI support (php-fpm, apache2 php handler servers)
- Middlewares
- Middleware Compositor
- A Simple Mux Builder (integrated with Pux)

### Environment

[](#environment)

```
// This creates $env array from $_SERVER, $_REQUEST, $_POST, $_GET ...
$env = Environment::createFromGlobals();
```

### Application

[](#application)

```
$app = function(array & $environment, array $response) {
    return [ 200, [ 'Content-Type' => 'text/plain' ], 'Hello World' ];
};
```

### Responder

[](#responder)

#### SAPIResponder

[](#sapiresponder)

You can integrate your application with SAPIResponder to support Apache2 php handler / php-fpm / fastcgi.

```
use Funk\Responder\SAPIResponder;

$fd = fopen('php://output', 'w');
$responder = new SAPIResponder($fd);
$responder->respond([ 200, [ 'Content-Type: text/plain' ], 'Hello World' ]);
fclose($fd);
```

```
use Funk\Responder\SAPIResponder;

$env = Environment::createFromGlobals();
$app = function(array & $environment, array $response) {
    return [ 200, [ 'Content-Type' => 'text/plain' ], 'Hello World' ];
};
$fd = fopen('php://output', 'w');
$responder = new SAPIResponder($fd);
$responder->respond($app($env, []));
fclose($fd);
```

### Middleware

[](#middleware)

- `Funk\Middleware\ContentNegotiationMiddleware`
- `Funk\Middleware\CORSMiddleware`
- `Funk\Middleware\GeocoderMiddleware`
- `Funk\Middleware\HeadMiddleware`
- `Funk\Middleware\TryCatchMiddleware`
- `Funk\Middleware\XHProfMiddleware`
- `Funk\Middleware\XHTTPMiddleware`

```
use Funk\Environment;
use Funk\Middleware\TryCacheMiddleware;

$app = function(array $environment, array $response) {
    return [ 200,  ['Content-Type' => 'text/html' ], 'Hello World' ];
};
$middleware = new TryCatchMiddleware($app);

$env = Environment::createFromGlobals();
$response = $middleware($env, [200, [], []]);
```

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

[](#contributing)

### Testing XHProf Middleware

[](#testing-xhprof-middleware)

Define your XHPROF\_ROOT in your `phpunit.xml`, you can copy `phpunit.xml.dist` to `phpunit.xml`, for example:

```

```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3cc34cde233b660869ff329ed8e20df611f75dfb61aab3e30889ac153d3e5e61?d=identicon)[c9s](/maintainers/c9s)

---

Top Contributors

[![c9s](https://avatars.githubusercontent.com/u/50894?v=4)](https://github.com/c9s "c9s (57 commits)")

---

Tags

httphttp-servermiddleware

### Embed Badge

![Health badge](/badges/phpsgi-funk/health.svg)

```
[![Health](https://phpackages.com/badges/phpsgi-funk/health.svg)](https://phpackages.com/packages/phpsgi-funk)
```

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78026.4M414](/packages/react-http)[php-http/curl-client

PSR-18 and HTTPlug Async client with cURL

48347.0M384](/packages/php-http-curl-client)[smi2/phpclickhouse

PHP ClickHouse Client

84310.1M71](/packages/smi2-phpclickhouse)

PHPackages © 2026

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