A FastCGI daemon written in PHP. Visit the project website for more documentation and guides.
Check out the project performance benchmarks to see how we got a "Hello, World!" Slim application to handle 5,500 rq/s.
Using this daemon, applications can stay alive between HTTP requests whilst operating behind the protection of a FastCGI enabled web server.
The daemon requires a handler to be defined that accepts request objects and returns PSR-7 or HttpFoundation responses.
The Speedfony Bundle integrates this daemon with the symfony2 framework. The Slim Adapter integrates this daemon with the Slim v3 framework. The Silex Adapter integrates this daemon with the Silex framework.
This project is currently in early stages of development and not considered stable. Importantly, this library currently lacks support for uploaded files.
Contributions and suggestions are welcome.
Below is an example of a simple 'Hello, World!' FastCGI application in PHP.
<?php // command.php
// Include the composer autoloader
require_once dirname(__FILE__) . '/../vendor/autoload.php';
use PHPFastCGI\FastCGIDaemon\ApplicationFactory;
use PHPFastCGI\FastCGIDaemon\Http\RequestInterface;
use Zend\Diactoros\Response\HtmlResponse;
// A simple kernel. This is the core of your application
$kernel = function (RequestInterface $request) {
// $request->getServerRequest() returns PSR-7 server request object
// $request->getHttpFoundationRequest() returns HTTP foundation request object
return new HtmlResponse('<h1>Hello, World!</h1>');
};
// Create your Symfony console application using the factory
$application = (new ApplicationFactory)->createApplication($kernel);
// Run the Symfony console application
$application->run();
If you wish to configure your FastCGI application to work with the apache web server, you can use the apache FastCGI module to process manage your application.
This can be done by creating a FCGI script that launches your application and inserting a FastCgiServer directive into your virtual host configuration.
#!/bin/bash
php /path/to/command.php run
FastCgiServer /path/to/web/root/script.fcgi
By default, the daemon will listen on FCGI_LISTENSOCK_FILENO, but it can also be configured to listen on a TCP address. For example:
php /path/to/command.php run --port=5000 --host=localhost
If you are using a web server such as nginx, you will need to use a process manager to monitor and run your application.