10
10
[ ![ Version] ( https://img.shields.io/github/v/tag/luzrain/phpstreamserver?label=Version&filter=v*.*.*&sort=semver&color=374151 )] ( ../../releases )
11
11
[ ![ Tests Status] ( https://img.shields.io/github/actions/workflow/status/luzrain/phpstreamserver/tests.yaml?label=Tests&branch=master )] ( ../../actions/workflows/tests.yaml )
12
12
13
- PHPStreamServer is a high performance event-loop based process manager, TCP, and UDP server written in PHP.
14
- With a built-in PSR-7 HTTP server you can easily integrate any PSR-7 compatible framework with it in no time.
15
- The built-in HTTP server is memory efficient no matter how large your HTTP requests and responses you operate are.
16
- PHPStreamServer is supports TLS encryption and the ability to implement custom protocols.
13
+ > [ !NOTE]
14
+ > This package is now under development
15
+
16
+ PHPStreamServer is a high performance event-loop based process manager, scheduler and webserver written in PHP.
17
+ This application server is designed to replace traditional setup for running php applications such as nginx, php-fpm, cron, supervisor.
17
18
18
19
#### Key features:
19
- - Supervisor;
20
+ - Process manager;
21
+ - Scheduler;
20
22
- Workers lifecycle management (reload by TTL, max memory, max requests, on exception, on each request);
21
- - PSR-7 HTTP server;
23
+ - HTTP/2
22
24
23
25
#### Requirements and limitations:
24
26
- Unix based OS (no windows support);
25
27
- php-posix and php-pcntl extensions;
26
- - php-uv extension is not required, but highly recommended for better performance.
28
+ - php-uv extension is not required, but recommended for better performance.
27
29
28
30
## Getting started
29
31
### Install composer packages
@@ -37,30 +39,32 @@ Here is example of simple http server.
37
39
``` php
38
40
// server.php
39
41
40
- use Luzrain\PHPStreamServer\Exception\HttpException;
42
+ use Amp\Http\Server\HttpErrorException;
43
+ use Amp\Http\Server\Request;
44
+ use Amp\Http\Server\RequestHandler\ClosureRequestHandler;
45
+ use Amp\Http\Server\Response;
41
46
use Luzrain\PHPStreamServer\Internal\WorkerProcess;
42
- use Luzrain\PHPStreamServer\Listener;
47
+ use Luzrain\PHPStreamServer\Plugin\HttpServer\HttpServer;
48
+ use Luzrain\PHPStreamServer\Plugin\HttpServer\Listen;
43
49
use Luzrain\PHPStreamServer\Server;
44
- use Luzrain\PHPStreamServer\Server\Connection\ConnectionInterface;
45
- use Luzrain\PHPStreamServer\Server\Http\Psr7\Response;
46
- use Luzrain\PHPStreamServer\Server\Protocols\Http;
47
- use Psr\Http\Message\ServerRequestInterface;
50
+ use Luzrain\PHPStreamServer\WorkerProcessDefinition;
48
51
49
52
$server = new Server();
50
- $server->addWorkersProcess(new WorkerProcess(
53
+
54
+ $server->addWorkersProcess(new WorkerProcessDefinition(
51
55
name: 'HTTP Server',
52
56
onStart: function (WorkerProcess $worker) {
53
- $worker->startListener( new Listener(
54
- listen: 'tcp://0.0.0.0:80',
55
- protocol: new Http( ),
56
- onMessage: function (ConnectionInterface $connection, ServerRequestInterface $data): void {
57
- $response = match ($data->getUri()->getPath()) {
58
- '/' => new Response(body: 'Hello world'),
59
- '/ping' => new Response(body: 'pong'),
60
- default => throw HttpException::createNotFoundException(),
61
- };
62
- $connection->send($response);
63
- } ,
57
+ $requestHandler = new ClosureRequestHandler(function (Request $request) : Response {
58
+ return match ($request->getUri()->getPath()) {
59
+ '/' => new Response(body: 'Hello world' ),
60
+ '/ping' => new Response(body: 'pong'),
61
+ default => throw new HttpErrorException(404),
62
+ };
63
+ });
64
+
65
+ $worker->startPlugin(plugin: new HttpServer(
66
+ listen: new Listen(listen: '0.0.0.0:8087'),
67
+ requestHandler: $requestHandler ,
64
68
));
65
69
},
66
70
));
0 commit comments