Skip to content

Commit 7d812b8

Browse files
Added usage documentation to README
1 parent 1e66ef1 commit 7d812b8

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,58 @@ The daemon requires a handler to be defined that accepts PSR-7 requests and retu
1616

1717
The [Speedfony Bundle](https://github.com/PHPFastCGI/SpeedfonyBundle) integrates this daemon with the symfony2 framework.
1818

19+
## Usage
20+
21+
Below is an example of a simple 'Hello, World!' FastCGI application in PHP.
22+
23+
```php
24+
<?php // application.php
25+
26+
// Include the composer autoloader
27+
require_once dirname(__FILE__) . '/../vendor/autoload.php';
28+
29+
use PHPFastCGI\FastCGIDaemon\Command\DaemonRunCommand;
30+
use PHPFastCGI\FastCGIDaemon\DaemonFactory;
31+
use Psr\Http\Message\ServerRequestInterface;
32+
use Symfony\Component\Console\Application;
33+
use Zend\Diactoros\Response\HtmlResponse;
34+
35+
// Create the dependencies for the DaemonRunCommand
36+
37+
// Dependency 1: The daemon factory
38+
$daemonFactory = new DaemonFactory();
39+
40+
// Dependency 2: A simple kernel. This is the core of your application
41+
$kernel = function (ServerRequestInterface $request) {
42+
return new HtmlResponse('<h1>Hello, World!</h1>');
43+
};
44+
45+
// Create an instance of DaemonRunCommand using the daemon factory and the kernel
46+
$command = new DaemonRunCommand('run', 'Run a FastCGI daemon', $daemonFactory, $kernel);
47+
48+
// Create a symfony console application and add the command
49+
$consoleApplication = new Application();
50+
$consoleApplication->add($command);
51+
52+
// Run the symfony console application
53+
$consoleApplication->run();
54+
```
55+
56+
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.
57+
58+
This can be done by creating an FCGI script that launches your application and inserting a FastCgiServer directive into your virtual host configuration.
59+
60+
```sh
61+
#!/bin/bash
62+
php /path/to/application.php run
63+
```
64+
65+
```
66+
FastCgiServer /path/to/web/root/index.fcgi
67+
```
68+
69+
If you are using a web server such as nginx, you will need to use a process manager to monitor and run your application.
70+
1971
## Current Status
2072

2173
This daemon is currently in early development stages and not considered stable. A stable release is expected by September 2015.

0 commit comments

Comments
 (0)