1. Go to this page and download the library: Download innmind/async-http-server library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
innmind / async-http-server example snippets
# server.php
declare(strict_types=1);
ind\OperatingSystem\OperatingSystem;
use Innmind\Http\{
ServerRequest,
Response,
Response\StatusCode,
};
use Innmind\Filesystem\Name;
use Innmind\Url\Path;
new class extends Main {
protected static function handle(ServerRequest $request, OperatingSystem $os): Response
{
return $os
->filesystem()
->mount(Path::of('somewhere/'))
->get(Name::of('some-file'))
->match(
static fn($file) => Response::of(
StatusCode::ok,
$request->protocolVersion(),
null,
$file->content(),
),
static fn() => Response::of(
StatusCode::notFound,
$request->protocolVersion(),
),
);
}
};
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.