PHP code example of asmblah / fast-cgi

1. Go to this page and download the library: Download asmblah/fast-cgi 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/ */

    

asmblah / fast-cgi example snippets




declare(strict_types=1);

use Asmblah\FastCgi\FastCgi;
use Asmblah\FastCgi\Launcher\PhpCgiLauncher;

php-cgi';

$dataDir = $baseDir . '/var/test';
@mkdir($dataDir, 0700, true);
$socketPath = $dataDir . '/php-cgi.test.sock';

$fastCgi = new FastCgi(
    baseDir: $baseDir,
    wwwDir: $wwwDir,
    socketPath: $socketPath,
    launcher: new PhpCgiLauncher($phpCgiBinaryPath)
);
$session = $fastCgi->start();

$response = $session->sendGetRequest(
    'my_script.php',
    '/path/to/my-page',
    [
        'greeting' => 'Hello',
    ]
);

// Will print "Hello from my front controller!".
print $response->getBody() . PHP_EOL;

$session->quit();



declare(strict_types=1);

print ($_GET['greeting'] ?? '(none)') . ' from my front controller!';



declare(strict_types=1);

use Asmblah\FastCgi\FastCgi;
use Asmblah\FastCgi\Launcher\PhpFpmLauncher;

 '/sbin/php-fpm';

$dataDir = $baseDir . '/var/test';
@mkdir($dataDir, 0700, true);
$socketPath = $dataDir . '/php-fpm.test.sock';
$logFilePath = $dataDir . '/php-fpm.log';

$configFilePath = $dataDir . '/php-fpm.conf';
file_put_contents($configFilePath, <<<CONFIG
[global]
error_log = $logFilePath

[www]
listen = $socketPath
pm = static
pm.max_children = 1

CONFIG
);

$fastCgi = new FastCgi(
    baseDir: $baseDir,
    wwwDir: $wwwDir,
    socketPath: $socketPath,
    launcher: new PhpFpmLauncher(
        $phpFpmBinaryPath,
        $configFilePath
    )
);
$session = $fastCgi->start();

$response = $session->sendGetRequest(
    'my_script.php',
    '/path/to/my-page',
    [
        'greeting' => 'Hello',
    ]
);

// Will print "Hello from my front controller!".
print $response->getBody() . PHP_EOL;

$session->quit();



declare(strict_types=1);

print ($_GET['greeting'] ?? '(none)') . ' from my front controller!';
shell
$ php test.php
Hello from my front controller!
shell
$ php test.php
Hello from my front controller!