├── .gitignore ├── PHPFastCGISpeedfonyBundle.php ├── .travis.yml ├── phpunit.xml.dist ├── Resources └── config │ └── services.yml ├── composer.json ├── Bridge └── KernelWrapper.php ├── DependencyInjection ├── Configuration.php └── PHPFastCGISpeedfonyExtension.php ├── LICENSE ├── Tests ├── Helper │ └── MockKernel.php └── Bridge │ └── KernelWrapperTest.php └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | /build/ 3 | /coverage/ 4 | /composer.lock 5 | 6 | -------------------------------------------------------------------------------- /PHPFastCGISpeedfonyBundle.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Tests 6 | 7 | 8 | 9 | 10 | Bridge 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Resources/config/services.yml: -------------------------------------------------------------------------------- 1 | services: 2 | php_fast_cgi_speedfony.kernel_wrapper: 3 | class: PHPFastCGI\SpeedfonyBundle\Bridge\KernelWrapper 4 | arguments: ['@kernel'] 5 | 6 | php_fast_cgi_speedfony.driver_container: 7 | class: PHPFastCGI\FastCGIDaemon\Driver\DriverContainer 8 | 9 | php_fast_cgi_speedfony.daemon_run_command: 10 | class: PHPFastCGI\FastCGIDaemon\Command\DaemonRunCommand 11 | arguments: ['@php_fast_cgi_speedfony.kernel_wrapper', '@php_fast_cgi_speedfony.driver_container', 'speedfony:run'] 12 | tags: 13 | - { name: console.command } 14 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "phpfastcgi/speedfony-bundle", 3 | "description": "A bundle to integrate a FastCGI daemon with the symfony2 framework", 4 | "keywords": ["speedfony", "bundle", "fastcgi", "server", "fast cgi", "daemon"], 5 | "type": "symfony-bundle", 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Andrew Carter", 10 | "email": "andrewcarter1992@gmail.com" 11 | } 12 | ], 13 | "require": { 14 | "php": ">=5.5.0", 15 | "symfony/http-kernel": "~2.7|~3.0", 16 | "symfony/dependency-injection": "~2.7|~3.0", 17 | "symfony/yaml": "~2.7|~3.0", 18 | "phpfastcgi/fastcgi-daemon": "^0.10" 19 | }, 20 | "require-dev": { 21 | "satooshi/php-coveralls": "dev-master" 22 | }, 23 | "autoload": { 24 | "psr-4": { 25 | "PHPFastCGI\\SpeedfonyBundle\\": "" 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Bridge/KernelWrapper.php: -------------------------------------------------------------------------------- 1 | kernel = $kernel; 24 | } 25 | 26 | /** 27 | * {@inheritdoc} 28 | */ 29 | public function handleRequest(RequestInterface $request) 30 | { 31 | $symfonyRequest = $request->getHttpFoundationRequest(); 32 | 33 | $symfonyResponse = $this->kernel->handle($symfonyRequest); 34 | $this->kernel->terminate($symfonyRequest, $symfonyResponse); 35 | 36 | return $symfonyResponse; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /DependencyInjection/Configuration.php: -------------------------------------------------------------------------------- 1 | root('php_fast_cgi_speedfony'); 22 | 23 | // Here you should define the parameters that are allowed to 24 | // configure your bundle. See the documentation linked above for 25 | // more information on that topic. 26 | 27 | return $treeBuilder; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /DependencyInjection/PHPFastCGISpeedfonyExtension.php: -------------------------------------------------------------------------------- 1 | processConfiguration($configuration, $configs); 24 | 25 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); 26 | $loader->load('services.yml'); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Andrew Carter 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /Tests/Helper/MockKernel.php: -------------------------------------------------------------------------------- 1 | callback = $callback; 24 | 25 | parent::__construct('dev', false); 26 | } 27 | 28 | /** 29 | * {@inheritdoc} 30 | */ 31 | public function registerBundles() 32 | { 33 | return []; 34 | } 35 | 36 | /** 37 | * {@inheritdoc} 38 | */ 39 | public function registerContainerConfiguration(LoaderInterface $loader) 40 | { 41 | } 42 | 43 | /** 44 | * {@inheritdoc} 45 | */ 46 | public function handle(Request $request, $type = 1, $catch = true) 47 | { 48 | return call_user_func($this->callback, $request); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Tests/Bridge/KernelWrapperTest.php: -------------------------------------------------------------------------------- 1 | '/hello'], $stream); 17 | 18 | $symfonyResponse = new HttpFoundationResponse('Hello World'); 19 | 20 | $kernel = new MockKernel(function (HttpFoundationRequest $symfonyRequest) use ($symfonyResponse) { 21 | $this->assertEquals('/hello', $symfonyRequest->getRequestUri()); 22 | 23 | return $symfonyResponse; 24 | }); 25 | 26 | $kernelWrapper = new KernelWrapper($kernel); 27 | 28 | $this->assertEquals($symfonyResponse, $kernelWrapper->handleRequest($request)); 29 | 30 | fclose($stream); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Speedfony Bundle 2 | 3 | [![Latest Stable Version](https://poser.pugx.org/phpfastcgi/speedfony-bundle/v/stable)](https://packagist.org/packages/phpfastcgi/speedfony-bundle) 4 | [![Build Status](https://travis-ci.org/PHPFastCGI/SpeedfonyBundle.svg?branch=master)](https://travis-ci.org/PHPFastCGI/FastCGIDaemon) 5 | [![Coverage Status](https://coveralls.io/repos/PHPFastCGI/SpeedfonyBundle/badge.svg?branch=master)](https://coveralls.io/r/PHPFastCGI/SpeedfonyBundle?branch=master) 6 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/PHPFastCGI/SpeedfonyBundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/PHPFastCGI/SpeedfonyBundle/?branch=master) 7 | [![Total Downloads](https://poser.pugx.org/phpfastcgi/speedfony-bundle/downloads)](https://packagist.org/packages/phpfastcgi/speedfony-bundle) 8 | 9 | A symfony2 bundle which allows applications to reduce overheads by exposing symfony's Request-Response structure to a FastCGI daemon. 10 | 11 | Visit the [project website](http://phpfastcgi.github.io/). 12 | 13 | ## Introduction 14 | 15 | Using this bundle, symfony2 applications can stay alive between HTTP requests whilst operating behind the protection of a FastCGI enabled web server. 16 | 17 | ## Current Status 18 | 19 | This daemon is currently in early development stages and not considered stable. 20 | 21 | Contributions and suggestions are welcome. 22 | 23 | ## Installing 24 | 25 | By turning your Symfony application into a FastCGI application, you can keep the application in memory between request cycles. 26 | 27 | To do this, open the terminal in your project directory and use composer to add the Speedfony Bundle to your dependencies. 28 | 29 | ```sh 30 | composer require "phpfastcgi/speedfony-bundle" 31 | ``` 32 | 33 | Next, register the bundle in your AppKernel.php file: 34 | 35 | ```php 36 | // app/AppKernel.php 37 | 38 | // ... 39 | class AppKernel extends Kernel 40 | { 41 | public function registerBundles() 42 | { 43 | $bundles = array( 44 | // ... 45 | new PHPFastCGI\SpeedfonyBundle\PHPFastCGISpeedfonyBundle(), 46 | ); 47 | 48 | // ... 49 | } 50 | // ... 51 | ``` 52 | 53 | ## Running the Daemon 54 | 55 | To start the daemon listening on port 5000 use the command below. Production mode is selected here for the purposes of generating accurate benchmarks. We do not recommend that you use this package in production mode as it is not yet stable. 56 | 57 | Check the FastCGI documentation for your chosen web server to find out how to configure it to use this daemon as a FastCGI application. 58 | 59 | ```sh 60 | php app/console speedfony:run --port 5000 --env="prod" 61 | ``` 62 | 63 | If you are using apache, you can configure the FastCGI module to launch and manage the daemon itself. For this to work you must omit the "--port" option from the command and the daemon will instead listen for incoming connections on FCGI_LISTENSOCK_FILENO (STDIN). 64 | 65 | For more information, please see the [server configuration documentation](https://github.com/PHPFastCGI/FastCGIDaemon#server-configuration). 66 | 67 | ## Updates 68 | 69 | ### v0.9.0 70 | - Upgraded FastCGIDaemon to v0.10.0 (auto-shutdown and shutdown flag support) 71 | 72 | ### v0.8.1 73 | - Bugfix: Upgraded FastCGIDaemon to v0.8.0 74 | 75 | ### v0.8.0 76 | - Symfony 3.0 component support 77 | 78 | ### v0.7.1 79 | - Service configuration file fix 80 | 81 | ### v0.7.0 82 | - Upgraded to use FastCGIDaemon v0.7.0 83 | 84 | ### v0.6.0 85 | - Upgraded to use FastCGIDaemon v0.6.0 86 | 87 | ### v0.5.0 88 | - Upgraded to use FastCGIDaemon v0.5.0 89 | 90 | ### v0.4.0 91 | - Upgraded to use FastCGIDaemon v0.4.0, renamed command to 'speedfony:run' 92 | 93 | ### v0.3.2 94 | - Bugfix: Composer dependency on FastCGIDaemon was too loose 95 | 96 | ### v0.3.1 97 | - Bugfix: Added call to terminate method on symfony kernel (so post response listeners now work) 98 | 99 | ### v0.3.0 100 | - Upgraded to use FastCGIDaemon v0.3.0 101 | 102 | ### v0.2.0 103 | - Upgraded to use FastCGIDaemon v0.2.0 and Symfony 2.7 with PSR-7 messages 104 | 105 | Contributions and suggestions are welcome. 106 | --------------------------------------------------------------------------------