PHP code example of phpfastcgi / fastcgi-daemon

1. Go to this page and download the library: Download phpfastcgi/fastcgi-daemon library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phpfastcgi / fastcgi-daemon example snippets


 // fastCGI_app.php

// Include the composer autoloader
tCGI\FastCGIDaemon\Http\RequestInterface;
use Zend\Diactoros\Response\HtmlResponse;

// A simple kernel. This is the core of your application
$kernel = function (RequestInterface $request) {    
    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();

 // fastCGI_app.php

emon\ApplicationFactory;
use PHPFastCGI\FastCGIDaemon\Http\RequestInterface;
use Symfony\Component\HttpFoundation\Response;

$kernel = function (RequestInterface $request) {
    $sfRequest = $request->getHttpFoundationRequest(); // returns HTTP Foundation request object
    
    return new Response('<h1>Hello, World!</h1>' . $sfRequest->getUri());
};

$application = (new ApplicationFactory)->createApplication($kernel);
$application->run();

 // fastCGI_app.php

os;
use Nyholm\Psr7Server\ServerRequestCreator;
use PHPFastCGI\FastCGIDaemon\ApplicationFactory;
use PHPFastCGI\FastCGIDaemon\Http\Request;
use PHPFastCGI\FastCGIDaemon\Http\RequestInterface;
use Zend\Diactoros\Response\HtmlResponse;

// Give the Request an instance of ServerRequestCreatorInterface filled with PSR-17 factories. 
// This is how we are independent of any PSR-7 implementation. 
Request::setServerRequestCreator(new ServerRequestCreator(
    new Diactoros\ServerRequestFactory,
    new Diactoros\UriFactory,
    new Diactoros\UploadedFileFactory,
    new Diactoros\StreamFactory
));

$kernel = function (RequestInterface $request) {
    $psr7Request = $request->getServerRequest(); // returns PSR-7 ServerRequestInterface
    
    return new HtmlResponse('<h1>Hello, World!</h1>' . $psr7Request->getRequestTarget());
};

$application = (new ApplicationFactory)->createApplication($kernel);
$application->run();
sh
#!/bin/bash

# Run the server
php /path/to/application.php run
bash
php /path/to/fastCGI_app.php run