PHPackages                             webgriffe/cgi-http-kernel - 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. webgriffe/cgi-http-kernel

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

webgriffe/cgi-http-kernel
=========================

Adapter from HttpKernelInterface to CGI. Originally was igorw/cgi-http-kerl which is abandoned.

v1.1.0(9y ago)026.2k1MITPHP

Since Mar 11Pushed 9y ago1 watchersCompare

[ Source](https://github.com/webgriffe/CgiHttpKernel)[ Packagist](https://packagist.org/packages/webgriffe/cgi-http-kernel)[ RSS](/packages/webgriffe-cgi-http-kernel/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (3)Versions (7)Used By (1)

CgiHttpKernel
=============

[](#cgihttpkernel)

Adapter from HttpKernelInterface to CGI.

The HttpKernelInterface is a lie
--------------------------------

[](#the-httpkernelinterface-is-a-lie)

You thought that you need to rewrite your whole application to use HttpFoundation in order to benefit from HttpKernelInterface functional testing?

Well, it turns out that you don't need that at all. Some very smart people came up with this thing called CGI (Common Gateway Interface) which defines an interface between a web server and a web application. It's great because it uses UNIX pipes for communication, which means it is also very easy to pretend to be a web server, and just call the app with any input and env vars on the command line by hand.

In PHP that works by using `php-cgi`, which fortunately ships with almost every PHP distribution. The most basic way of calling it on the command line is this:

```
$ php-cgi hello.php

```

If you want to learn how to do more advanced stuff, read the fucking CGI spec.

So what does this have to do with HttpKernelInterface? CGI and that interface do pretty much the same thing, they abstract communication between web server and app. The kernel interface does this within PHP, CGI does it in a language agnostic way.

The CgiHttpKernel translates between those two interfaces. As a user of the library you interact with it as if it were a true HttpKernelInterface app, but in the background it will actually go ahead and call `php-cgi` on the command line, parse the output, and return a `Response` instance.

For example:

```
$kernel = new CgiHttpKernel(__DIR__.'/../phpBB');

$request = Request::create('/index.php');
$response = $kernel->handle($request);

var_dump($response->getContent());
```

You can also pass a second argument to the constructor if you want all requests to go through a front controller.

```
$kernel = new CgiHttpKernel(__DIR__.'/../web', 'app.php');

$request = Request::create('/foo');
$response = $kernel->handle($request);
```

You can also set the php-cgi binary path and a process timeout (which by default is set to 60 seconds):

```
$kernel = new CgiHttpKernel(__DIR__.'/../web', 'app.php', '/path/to/php-cgi', 300);

// Or set the timeout to null to disable the timeout at all
$kernel = new CgiHttpKernel(__DIR__.'/../web', 'app.php', '/path/to/php-cgi', null);
```

The real power however comes from using libraries that integrate with the HttpKernelInterface, such as `Symfony\Component\HttpKernel\Client`.

```
$kernel = new CgiHttpKernel(__DIR__.'/../phpBB');
$client = new Client($kernel);

$crawler = $client->request('GET', '/index.php');
$this->assertGreaterThan(0, $crawler->filter('.topiclist')->count());
```

Is it really a lie?
-------------------

[](#is-it-really-a-lie)

Not really. The CgiHttpKernel only makes sense for functional testing, since it is quite slow. It is slow because it must spawn a new process for every request. This is also the reason why some very smart people came up with FastCGI, which is like CGI but faster.

FastCGI allows the app to start a long-running process that listens on a port and thus does not have the process spawning overhead. In PHP land this is usually managed by PHP-FPM, aka FastCGI Process Manager.

FastCGI is good for production but not really practical for testing since it needs to run in a separate process, listen on a port, requires configuration, etc.

However, there is an [FcgiHttpKernel](https://github.com/igorw/FcgiHttpKernel)that ports the idea of this project to FastCGI. It may in fact become useful for tests.

When to use CgiHttpKernel?
--------------------------

[](#when-to-use-cgihttpkernel)

It is mainly intended to write functional tests for legacy applications. That will hopefully enable you to refactor your legacy code with some confidence of not breaking stuff.

Good luck.

Specifics
---------

[](#specifics)

### Attributes

[](#attributes)

Request attributes are serialized and provided to the target script through the `SYMFONY_ATTRIBUTES` env variable. This means that it can get the original attributes as follows:

```
$attributes = unserialize($_SERVER['SYMFONY_ATTRIBUTES']);

```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 85.1% 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 ~295 days

Recently: every ~369 days

Total

6

Last Release

3333d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/eca104631fd7f6aff6d399ca16458c4d9814770756af0ecca22ffe2b1c5704d3?d=identicon)[mmenozzi](/maintainers/mmenozzi)

---

Top Contributors

[![igorw](https://avatars.githubusercontent.com/u/88061?v=4)](https://github.com/igorw "igorw (40 commits)")[![mmenozzi](https://avatars.githubusercontent.com/u/1199914?v=4)](https://github.com/mmenozzi "mmenozzi (3 commits)")[![ftassi](https://avatars.githubusercontent.com/u/176622?v=4)](https://github.com/ftassi "ftassi (1 commits)")[![hakre](https://avatars.githubusercontent.com/u/378849?v=4)](https://github.com/hakre "hakre (1 commits)")[![ktomk](https://avatars.githubusercontent.com/u/352517?v=4)](https://github.com/ktomk "ktomk (1 commits)")[![LucaGallinari](https://avatars.githubusercontent.com/u/5822554?v=4)](https://github.com/LucaGallinari "LucaGallinari (1 commits)")

### Embed Badge

![Health badge](/badges/webgriffe-cgi-http-kernel/health.svg)

```
[![Health](https://phpackages.com/badges/webgriffe-cgi-http-kernel/health.svg)](https://phpackages.com/packages/webgriffe-cgi-http-kernel)
```

###  Alternatives

[nelmio/api-doc-bundle

Generates documentation for your REST API from attributes

2.3k63.6M233](/packages/nelmio-api-doc-bundle)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k48.1M236](/packages/api-platform-core)[friendsofsymfony/http-cache-bundle

Set path based HTTP cache headers and send invalidation requests to your HTTP cache

43813.2M47](/packages/friendsofsymfony-http-cache-bundle)[api-platform/state

API Platform state interfaces

223.4M57](/packages/api-platform-state)[api-platform/validator

API Platform validator component

223.2M10](/packages/api-platform-validator)[swoole-bundle/swoole-bundle

Open/Swoole Symfony Bundle

6650.4k](/packages/swoole-bundle-swoole-bundle)

PHPackages © 2026

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