Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Feb 18, 2020
1 parent 51e228b commit 5e75761
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 69 deletions.
12 changes: 12 additions & 0 deletions docs/classes/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ Remote address or unix socket path.

Local server address or unix socket path.

## `isUnix(): bool`

`true` if the client is connected via a Unix socket, `false` if TCP socket.

## `isEncrypted(): bool`

`true` if the client is encrypted, `false` if plaintext.
Expand All @@ -58,6 +62,14 @@ If the client is encrypted, returns the `TlsInfo` object. Null is returned for p

Integer mask of `Client::CLOSED_*` constants.

## `getExpirationTime(): int`

Timestamp when the client will automatically be closed if no further activity is received on the connection.

## `updateExpirationTime(int $expiresAt): void`

Sets the timestamp when the client should automatically be closed if no further activity is received on the connection.

## `onClose(callable $onClose): void`

Attaches a callback invoked with this client closes.
Expand Down
11 changes: 7 additions & 4 deletions docs/classes/server.md → docs/classes/http-server.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
---
title: Server
permalink: /classes/server
title: HttpServer
permalink: /classes/http-server
---

* Table of Contents
{:toc}

The `Server` instance controls the whole listening and dispatches the parsed requests.
The `HttpServer` instance controls the whole listening and dispatches the parsed requests.

The `Server` class has a [custom debug output](http://php.net/manual/en/language.oop5.magic.php#object.debuginfo), which isn't part of the public API and which shouldn't be relied upon.
The `HttpServer` class has a [custom debug output](http://php.net/manual/en/language.oop5.magic.php#object.debuginfo), which isn't part of the public API and which shouldn't be relied upon.

{:.note}
> This class was previously named `Server`. An alias to `Server` name exists for backward-compatibility with v1.x, but may be removed in a future version.
## Constructor

Expand Down
9 changes: 5 additions & 4 deletions docs/classes/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ The `http-server` package provides a set of classes and interfaces:

- [`Client`](client.md) — Client connection related information
- [`HttpDriver`](http-driver.md) — Driver for interaction with the raw socket
- [`HttpServer`](http-server.md) — The server, tying everything together
- [`Options`](options.md) — Accessor of options
- [`Request`](request.md) — Request class for request handler callables
- [`Push`](push.md) — Represents resourced pushed to the client through responses
- [`Request`](request.md) — Request class representing client requests
- [`RequestBody`](request-body.md) — Request body
- [`RequestHandler`](request-handler.md) — Request handler interface
- [`Response`](response.md) — General response interface for responder callables
- [`Server`](server.md) — The server, tying everything together
- [`RequestHandler`](request-handler.md) — Request handler interface
- [`Response`](response.md) — Response class for responding to client requests in request handlers
- [`ServerObserver`](server-observer.md) — Registers method to be notified upon Server state changes
- [`Trailers`](trailers.md) — Access request trailers
2 changes: 1 addition & 1 deletion docs/classes/middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ $middleware = new class implements Middleware {
}
};

$server = new Server($servers, Middleware\stack($handler, $middleware), $logger);
$server = new HttpServer($servers, Middleware\stack($handler, $middleware), $logger);
```
82 changes: 41 additions & 41 deletions docs/classes/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,56 @@ Sets the maximum number of connections to allow from a single IP address.
{:.note}
> Default connections per IP limit is `30`.
## `getConnectionTimeout(): int`
## `getHttp1Timeout(): int`

Returns amount of time in seconds a connection may be idle before it is automatically closed.
Returns amount of time in seconds an HTTP/1.x connection may be idle before it is automatically closed.

{:.note}
> Default connection timeout is `15` seconds.
> Default HTTP/1.x connection timeout is `15` seconds.
## `withConnectionTimeout(int $seconds): Options`
## `withHttp1Timeout(int $seconds): Options`

Sets the number of seconds a connection may be idle before it is automatically closed.
Sets the number of seconds an HTTP/1.x connection may be idle before it is automatically closed.

{:.warning}
> Connection timeout must be greater than or equal to one second.
> HTTP/1.x connection timeout must be greater than or equal to one second.
{:.note}
> Default connection timeout is `15` seconds.
> Default HTTP/1.x connection timeout is `15` seconds.
## `getHttp2Timeout(): int`

Returns amount of time in seconds an HTTP/2` connection may be idle before it is automatically closed.

{:.note}
> Default HTTP/2 connection timeout is `60` seconds.
## `withHttp2Timeout(int $seconds): Options`

Sets the number of seconds an HTTP/2 connection may be idle before it is automatically closed.

{:.warning}
> HTTP/2 connection timeout must be greater than or equal to one second.
{:.note}
> Default HTTP/2 connection timeout is `60` seconds.
## `getTlsSetupTimeout(): int`

Returns amount of time in seconds that can elapse during TLS setup before a connection is automatically closed.

{:.note}
> Default TLS setup timeout is `5` seconds.
## `withTlsSetupTimeout(int $seconds): Options`

Sets the number of seconds that may elapse during TLS setup before a connection is automatically closed.

{:.warning}
> TLS setup timeout must be greater than or equal to one second.
{:.note}
> Default TLS setup timeout is `5` seconds.
## `getBodySizeLimit(): int`

Expand Down Expand Up @@ -125,40 +159,6 @@ Sets the maximum number of concurrent HTTP/2 streams per connection.
{:.note}
> Default concurrent streams limit is `20`.
## `getMinimumAverageFrameSize(): int`

Returns minimum average frame size required if more than the maximum number of frames per second are received on an HTTP/2 connection.

{:.note}
> Default minimum average frame size is `1024` bytes (1k).
## `withMinimumAverageFrameSize(int $size): Options`

Sets minimum average frame size required if more than the maximum number of frames per second are received on an HTTP/2 connection.

{:.warning}
> Minimum average frame size must be greater than zero.
{:.note}
> Default minimum average frame size is `1024` bytes (1k).
## `getFramesPerSecondLimit(): int`

Returns the maximum number of HTTP/2 frames per second before the average length minimum is enforced.

{:.note}
> Default frames per second limit is `60`.
## `withFramesPerSecondLimit(int $frames): Options`

Sets the maximum number of HTTP/2 frames per second before the average length minimum is enforced.

{:.warning}
> Maximum number of HTTP/2 frames per second setting must be greater than zero.
{:.note}
> Default frames per second limit is `60`.
## `getChunkSize(): int`

Returns the maximum number of bytes to read from a client per read.
Expand Down
32 changes: 32 additions & 0 deletions docs/classes/push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: Push
permalink: /classes/push
---

* Table of Contents
{:toc}

The **`Push`** class represents a pushed resource in a [`Response`](response.md). `Push` objects are not created by the user, rather resources should be pushed to the client using the `Response::push()` method. An array of `Push` objects is returned by the `Response::getPushes()` method.

## `getHeaders(): string[][]`

Returns the headers as a string-indexed array of arrays of strings or an empty array if no headers have been set.

## `hasHeader(string $name): bool`

Checks if given header exists.

## `getHeaderArray(string $name): string[]`

Returns the array of values for the given header or an empty array if the header does not exist.

## `getHeader(string $name): ?string`

Returns the value of the given header.
If multiple headers are present for the named header, only the first header value will be returned.
Use `getHeaderArray()` to return an array of all values for the particular header.
Returns `null` if the header does not exist.

## `getUri(): Psr\Http\Message\UriInterface`

Returns the pushed resource's [`URI`](https://www.php-fig.org/psr/psr-7/#35-psrhttpmessageuriinterface).
2 changes: 1 addition & 1 deletion docs/classes/request-handler.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $servers = [
Socket\listen("[::]:1337"),
];

$server = new Server($servers, new CallableRequestHandler(function (Request $request) {
$server = new HttpServer($servers, new CallableRequestHandler(function (Request $request) {
return new Response(Status::OK, [
"content-type" => "text/plain; charset=utf-8"
], "Hello, World!");
Expand Down
20 changes: 12 additions & 8 deletions docs/classes/request.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ The **`Request`** class represents an HTTP request. It's used in [request handle

```php
public function __construct(
Client $client,
string $method,
Psr\Http\Message\UriInterface $uri,
string[] | string[][] $headers = [],
RequestBody | Amp\ByteStream\InputStream | string | null $body = null,
Client $client,
string $method,
Psr\Http\Message\UriInterface $uri,
string[] | string[][] $headers = [],
RequestBody | Amp\ByteStream\InputStream | string | null $body = null,
string $protocol = "1.1",
?Trailers $trailers = null
)
Expand Down Expand Up @@ -110,7 +110,7 @@ Sets the stream for the message body
> Setting an [`InputStream`](https://amphp.org/byte-stream/#inputstream) will remove the `Content-Length` header.
> If you know the exact content length of your stream, you can add a `content-length` header _after_ calling `setBody()`.
If `$stringOrStream` value is not valid, [`\TypeError`](http://php.net/manual/en/class.typeerror.php) is thrown.
If `$stringOrStream` value is not valid, [`\TypeError`](http://php.net/manual/en/class.typeerror.php) is thrown.

## `getCookies(): RequestCookie[]`

Expand All @@ -134,20 +134,24 @@ Removes a cookie from the request.

Returns an array of all the attributes stored in the request's mutable local storage.

## `removeAttributes(): array`

Removes all request attributes from the request's mutable local storage.

## `hasAttribute(string $name): bool`

Check whether an attribute with the given name exists in the request's mutable local storage.

## `getAttribute(string $name): mixed`

Retrieve a variable from the request's mutable local storage.
Retrieve a variable from the request's mutable local storage.

{:.note}
> Name of the attribute should be namespaced with a vendor and package namespace, like classes.
## `setAttribute(string $name, mixed $value): void`

Assign a variable to the request's mutable local storage.
Assign a variable to the request's mutable local storage.

{:.note}
> Name of the attribute should be namespaced with a vendor and package namespace, like classes.
Expand Down
8 changes: 4 additions & 4 deletions docs/classes/response.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ The **`Response`** class represents an HTTP response. The **`Response`** promise

```php
public function __construct(
int $code = Status::OK,
string[] | string[][] $headers = [],
int $code = Status::OK,
string[] | string[][] $headers = [],
Amp\ByteStream\InputStream | string | null $stringOrStream = null,
?Trailers $trailers = null
)
Expand Down Expand Up @@ -110,13 +110,13 @@ Adds a [cookie](https://amphp.org/http/cookies) to the response.

Removes a [cookie](https://amphp.org/http/cookies) from the response.

## `getPush(): string[][]`
## `getPushes(): Push[]`

Returns list of push resources in an associative map:

```php
[
string $url => [ Psr\Http\Message\UriInterface $uri, string[][] $headers ],
string $url => `Push`,
]
```

Expand Down
4 changes: 2 additions & 2 deletions docs/classes/server-observer.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ Classes aggregating request handlers SHOULD check if they implement `ServerObser
* Table of Contents
{:toc}

## `onStart(Server): Promise`
## `onStart(HttpServer $server): Promise`

Invoked when the server is starting.
Server sockets have been opened, but are not yet accepting client connections.
This method should be used to set up any necessary state for responding to requests, including starting loop watchers such as timers.
Accepting connections is deferred until the returned promise resolves.

## `onStop(Server): Promise`
## `onStop(HttpServer $server): Promise`

Invoked when the server has initiated stopping.
No further requests are accepted and any connected clients should be closed gracefully and any loop watchers cancelled.
4 changes: 2 additions & 2 deletions docs/classes/trailers.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public function __construct(

Returns the declared trailer fields to be expected in the trailers. If given, the field names in the trailers must match exactly.

## `awaitMessage(): Promise<Message>`
## `await(): Promise<Message>`

Returns a promise that is resolved with an instance of `Amp\Http\Message` when the trailers are received.
Returns a promise that is resolved with an instance of `Amp\Http\Message` when the trailers are received.
4 changes: 2 additions & 2 deletions docs/production.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ permalink: /production

## General

- Set your `ulimit -n` (maximum open file descriptors) high enough to manage all your connections. Recommended is at least `$workers * (Options->getConnectionLimit() + 100)`. [100 is an arbitrary number usually big enough for all the persisting file descriptors. If not enough, add more.]
- Set your `ulimit -n` (maximum open file descriptors) high enough to manage all your connections. Recommended is at least `(Options->getConnectionLimit() + 100)`. [100 is an arbitrary number usually big enough for all the persisting file descriptors. If not enough, add more.]
- In case you are using a properly configured load-balancer in front of Amp's HTTP servers, you should set the number of connections near to the maximum the host system can handle.
- Amp's HTTP server has a [static content server](https://github.com/amphp/http-server-static-content), which isn't too bad (use some [extension](https://github.com/amphp/file#optional-extension-backends) if you use it!), but for heavy loads, a CDN is recommended.
- Amp's HTTP server has a [static content server](https://github.com/amphp/http-server-static-content), which is acceptable for lighter loads (use some [extension](https://github.com/amphp/file#optional-extension-backends) if you use it!), but for heavy loads, a CDN is recommended.
- Avoid a low [`memory_limit`](http://php.net/manual/en/ini.core.php#ini.memory-limit) setting, it is one of the few things able to kill the server ungracefully. If you have a memory leak, fix it, instead of relying on the master process to restart it.

## Options
Expand Down

0 comments on commit 5e75761

Please sign in to comment.