Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update amp #19

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,19 @@ services:

matrix:
include:
-
env:
- DOCKER_PHP_VERSION="php71"
-
env:
- DOCKER_PHP_VERSION="php72"
-
env:
- DOCKER_PHP_VERSION="php73"
-
env:
- DOCKER_PHP_VERSION="php74jit"
- DOCKER_PHP_VERSION="php74"
-
env:
- DOCKER_PHP_VERSION="php8jit"
- DOCKER_PHP_VERSION="php80"
allow_failures:
-
env:
- DOCKER_PHP_VERSION="php8jit"
- DOCKER_PHP_VERSION="php80"


before_install:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.org/torinaki/aerys-benchmark.svg?branch=master)](https://travis-ci.org/torinaki/aerys-benchmark)
[![Build Status](https://travis-ci.org/dbalabka/aerys-benchmark.svg?branch=master)](https://travis-ci.org/torinaki/aerys-benchmark)

About
=====
Expand Down
3 changes: 1 addition & 2 deletions aerys/v0.8/composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"require": {
"amphp/http-server": "^0.8",
"amphp/cluster": "dev-master"
"amphp/http-server": "^0.8.3"
},
"minimum-stability": "dev",
"prefer-stable": true
Expand Down
50 changes: 50 additions & 0 deletions aerys/v0.8/server-super-tiny.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
/*
* (c) 2018, Dmitrijs Balabka
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

require __DIR__ . '/vendor/autoload.php';

// This is a very simple HTTP server that just prints a message to each client that connects.
// It doesn't check whether the client sent an HTTP request.

// You might notice that your browser opens several connections instead of just one, even when only making one request.

use Amp\Loop;
use Amp\Socket\ServerSocket;
use function Amp\asyncCoroutine;

Loop::run(static function () {
$requestCount = 0;
$clientHandler = asyncCoroutine(static function (ServerSocket $socket) use (&$requestCount) {
list($ip, $port) = explode(':', $socket->getRemoteAddress());

$buffer = '';
while (($chunk = yield $socket->read()) !== null) {
$buffer .= $chunk;
if (\substr($buffer, -4, 4) === "\r\n\r\n") {
$date = \gmdate('D, d M Y H:i:s', \time()) . ' GMT';
$body = 'Hello world!';
$bodyLength = \strlen($body);
$requestCount++;
echo $requestCount;
yield $socket->write("HTTP/1.1 200 OK\r\nContent-Type: text/plain; Charset=utf-8\r\nX-Powered-By: AerysServer\r\nConnection: keep-alive\r\nContent-Length: ${bodyLength}\r\nKeep-Alive: timeout=10000\r\nDate: ${date}\r\n\r\n${body}\r\n\r\n\r\n\r\n");
}
}
});

$server = Amp\Socket\listen('0.0.0.0:8080');

echo 'Listening for new connections on ' . $server->getAddress() . ' ...' . PHP_EOL;

while ($socket = yield $server->accept()) {
$clientHandler($socket);
// if ($requestCount > 4) {
// exit;
// }
}
});
11 changes: 6 additions & 5 deletions aerys/v0.8/server-tiny.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Amp\Http\Server\Request;
use Amp\Http\Server\Response;
use Amp\Http\Status;
use Amp\Loop;
use Amp\Socket;
use Psr\Log\NullLogger;
use Amp\Http\Server\Options;
Expand All @@ -23,11 +24,11 @@
;

$sockets = [
Socket\listen("0.0.0.0:8080"),
Socket\listen('0.0.0.0:8080'),
];
$server = new Server(
$sockets,
new CallableRequestHandler(function (Request $request) {
new CallableRequestHandler(static function (Request $request) {
if ($request->getUri()) {
$data = 'Hello world!';
$status = Status::OK;
Expand All @@ -48,13 +49,13 @@
$options
);

\Amp\Loop::run(function () use ($server) {
Loop::run(static function () use ($server) {
yield $server->start();

// Stop the server gracefully when SIGINT is received.
// This is technically optional, but it is best to call Server::stop().
Amp\Loop::onSignal(\SIGINT, function (string $watcherId) use ($server) {
Amp\Loop::cancel($watcherId);
Loop::onSignal(\SIGINT, function (string $watcherId) use ($server) {
Loop::cancel($watcherId);
yield $server->stop();
});
});
34 changes: 0 additions & 34 deletions aerys/v0.8/server.php

This file was deleted.

7 changes: 7 additions & 0 deletions aerys/v1.x/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"require": {
"amphp/http-server": "v1.1.2"
},
"minimum-stability": "dev",
"prefer-stable": true
}
50 changes: 50 additions & 0 deletions aerys/v1.x/server-super-tiny.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
/*
* (c) 2018, Dmitrijs Balabka
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

require __DIR__ . '/vendor/autoload.php';

// This is a very simple HTTP server that just prints a message to each client that connects.
// It doesn't check whether the client sent an HTTP request.

// You might notice that your browser opens several connections instead of just one, even when only making one request.

use Amp\Loop;
use Amp\Socket\ServerSocket;
use function Amp\asyncCoroutine;

Loop::run(static function () {
$requestCount = 0;
$clientHandler = asyncCoroutine(static function (ServerSocket $socket) use (&$requestCount) {
list($ip, $port) = explode(':', $socket->getRemoteAddress());

$buffer = '';
while (($chunk = yield $socket->read()) !== null) {
$buffer .= $chunk;
if (\substr($buffer, -4, 4) === "\r\n\r\n") {
$date = \gmdate('D, d M Y H:i:s', \time()) . ' GMT';
$body = 'Hello world!';
$bodyLength = \strlen($body);
$requestCount++;
echo $requestCount;
yield $socket->write("HTTP/1.1 200 OK\r\nContent-Type: text/plain; Charset=utf-8\r\nX-Powered-By: AerysServer\r\nConnection: keep-alive\r\nContent-Length: ${bodyLength}\r\nKeep-Alive: timeout=10000\r\nDate: ${date}\r\n\r\n${body}\r\n\r\n\r\n\r\n");
}
}
});

$server = Amp\Socket\listen('0.0.0.0:8080');

echo 'Listening for new connections on ' . $server->getAddress() . ' ...' . PHP_EOL;

while ($socket = yield $server->accept()) {
$clientHandler($socket);
// if ($requestCount > 4) {
// exit;
// }
}
});
62 changes: 62 additions & 0 deletions aerys/v1.x/server-tiny.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
declare(strict_types=1);

use Amp\Http\Server\RequestHandler\CallableRequestHandler;
use Amp\Http\Server\Server;
use Amp\Http\Server\Request;
use Amp\Http\Server\Response;
use Amp\Http\Status;
use Amp\Loop;
use Amp\Socket;
use Psr\Log\NullLogger;
use Amp\Http\Server\Options;

require_once __DIR__ . '/vendor/autoload.php';

$options = (new Options())
// help avoid connection errors during benchmark
->withConnectionsPerIpLimit(100)
// to emulate NodeJS behavior
->withConnectionTimeout(10000)
->withoutCompression()
->withoutHttp2Upgrade()
// TODO: options do not support this param?
// ->withMaxRequestsPerConnection(PHP_INT_MAX)
;

$sockets = [
Socket\listen('0.0.0.0:8080'),
];
$server = new Server(
$sockets,
new CallableRequestHandler(static function (Request $request) {
if ($request->getUri()) {
$data = 'Hello world!';
$status = Status::OK;
} else {
$data = 'Not Found';
$status = Status::NOT_FOUND;
}
return new Response(
$status,
[
'Content-Type' => 'text/plain; charset=utf-8',
'X-Powered-By' => 'AerysServer',
],
$data
);
}),
new NullLogger(),
$options
);

Loop::run(static function () use ($server) {
yield $server->start();

// Stop the server gracefully when SIGINT is received.
// This is technically optional, but it is best to call Server::stop().
Loop::onSignal(SIGINT, function (string $watcherId) use ($server) {
Loop::cancel($watcherId);
yield $server->stop();
});
});
7 changes: 7 additions & 0 deletions aerys/v2.x/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"require": {
"amphp/http-server": "v2.0.0-rc3"
},
"minimum-stability": "dev",
"prefer-stable": true
}
53 changes: 53 additions & 0 deletions aerys/v2.x/server-super-tiny.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
/*
* (c) 2018, Dmitrijs Balabka
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

require __DIR__ . '/vendor/autoload.php';

// This is a very simple HTTP server that just prints a message to each client that connects.
// It doesn't check whether the client sent an HTTP request.

// You might notice that your browser opens several connections instead of just one, even when only making one request.

use Amp\Loop;
use Amp\Socket\ResourceSocket;
use Amp\Socket\Server;
use function Amp\asyncCoroutine;

Loop::run(static function () {
$requestCount = 0;
$clientHandler = asyncCoroutine(function (ResourceSocket $socket) use (&$requestCount) {
$address = $socket->getRemoteAddress();
$ip = $address->getHost();
$port = $address->getPort();

$buffer = '';
while (($chunk = yield $socket->read()) !== null) {
$buffer .= $chunk;
if (\substr($buffer, -4, 4) === "\r\n\r\n") {
$date = \gmdate('D, d M Y H:i:s', \time()) . ' GMT';
$body = 'Hello world!';
$bodyLength = \strlen($body);
$requestCount++;
echo $requestCount;
yield $socket->write("HTTP/1.1 200 OK\r\nContent-Type: text/plain; Charset=utf-8\r\nX-Powered-By: AerysServer\r\nConnection: keep-alive\r\nContent-Length: ${bodyLength}\r\nKeep-Alive: timeout=10000\r\nDate: ${date}\r\n\r\n${body}\r\n\r\n\r\n\r\n");
}
}
});

$server = Server::listen('0.0.0.0:8080');

echo 'Listening for new connections on ' . $server->getAddress() . " ..." . PHP_EOL;

while ($socket = yield $server->accept()) {
$clientHandler($socket);
// if ($requestCount > 4) {
// exit;
// }
}
});
Loading