Skip to content

Commit

Permalink
Readme update
Browse files Browse the repository at this point in the history
  • Loading branch information
luzrain committed Sep 2, 2024
1 parent af78cef commit cfc1275
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@
[![Version](https://img.shields.io/github/v/tag/luzrain/phpstreamserver?label=Version&filter=v*.*.*&sort=semver&color=374151)](../../releases)
[![Tests Status](https://img.shields.io/github/actions/workflow/status/luzrain/phpstreamserver/tests.yaml?label=Tests&branch=master)](../../actions/workflows/tests.yaml)

PHPStreamServer is a high performance event-loop based process manager, TCP, and UDP server written in PHP.
With a built-in PSR-7 HTTP server you can easily integrate any PSR-7 compatible framework with it in no time.
The built-in HTTP server is memory efficient no matter how large your HTTP requests and responses you operate are.
PHPStreamServer is supports TLS encryption and the ability to implement custom protocols.
> [!NOTE]
> This package is now under development
PHPStreamServer is a high performance event-loop based process manager, scheduler and webserver written in PHP.
This application server is designed to replace traditional setup for running php applications such as nginx, php-fpm, cron, supervisor.

#### Key features:
- Supervisor;
- Process manager;
- Scheduler;
- Workers lifecycle management (reload by TTL, max memory, max requests, on exception, on each request);
- PSR-7 HTTP server;
- HTTP/2

#### Requirements and limitations:
- Unix based OS (no windows support);
- php-posix and php-pcntl extensions;
- php-uv extension is not required, but highly recommended for better performance.
- php-uv extension is not required, but recommended for better performance.

## Getting started
### Install composer packages
Expand All @@ -37,30 +39,32 @@ Here is example of simple http server.
```php
// server.php

use Luzrain\PHPStreamServer\Exception\HttpException;
use Amp\Http\Server\HttpErrorException;
use Amp\Http\Server\Request;
use Amp\Http\Server\RequestHandler\ClosureRequestHandler;
use Amp\Http\Server\Response;
use Luzrain\PHPStreamServer\Internal\WorkerProcess;
use Luzrain\PHPStreamServer\Listener;
use Luzrain\PHPStreamServer\Plugin\HttpServer\HttpServer;
use Luzrain\PHPStreamServer\Plugin\HttpServer\Listen;
use Luzrain\PHPStreamServer\Server;
use Luzrain\PHPStreamServer\Server\Connection\ConnectionInterface;
use Luzrain\PHPStreamServer\Server\Http\Psr7\Response;
use Luzrain\PHPStreamServer\Server\Protocols\Http;
use Psr\Http\Message\ServerRequestInterface;
use Luzrain\PHPStreamServer\WorkerProcessDefinition;

$server = new Server();
$server->addWorkersProcess(new WorkerProcess(

$server->addWorkersProcess(new WorkerProcessDefinition(
name: 'HTTP Server',
onStart: function (WorkerProcess $worker) {
$worker->startListener(new Listener(
listen: 'tcp://0.0.0.0:80',
protocol: new Http(),
onMessage: function (ConnectionInterface $connection, ServerRequestInterface $data): void {
$response = match ($data->getUri()->getPath()) {
'/' => new Response(body: 'Hello world'),
'/ping' => new Response(body: 'pong'),
default => throw HttpException::createNotFoundException(),
};
$connection->send($response);
},
$requestHandler = new ClosureRequestHandler(function (Request $request) : Response {
return match ($request->getUri()->getPath()) {
'/' => new Response(body: 'Hello world'),
'/ping' => new Response(body: 'pong'),
default => throw new HttpErrorException(404),
};
});

$worker->startPlugin(plugin: new HttpServer(
listen: new Listen(listen: '0.0.0.0:8087'),
requestHandler: $requestHandler,
));
},
));
Expand Down

0 comments on commit cfc1275

Please sign in to comment.