Using PHPFastCGI, applications can stay alive between HTTP requests whilst operating behind the protection of a FastCGI enabled web server.
PHPFastCGI is a collection of several packages including a core FastCGIDaemon package and easy integration adapters built for the Symfony, Silex and Slim frameworks.
Before doing this, please read the post on things to consider when using PHPFastCGI with your application.
Below is an example of a simple ‘Hello, World!’ FastCGI application in PHP using the core FastCGIDaemon package:
With NGINX, you need to use a process manager such as supervisord to manage instances of your application. Have a look at AstroSplash for an example supervisord configuration.
Below is an example of the modification that you would make to the Symfony NGINX configuration. The core principle is to replace the PHP-FPM reference with one to a cluster of workers.
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.
Here is an example script.fcgi
:
Or with Symfony:
In your configuration, you can use the FastCgiServer directive to inform Apache of your application.
By default, the daemon will listen on FCGI_LISTENSOCK_FILENO, but it can also be configured to listen on a TCP address. For example:
Or with Symfony: