An open API service indexing awesome lists of open source software.

https://github.com/vosaka-php/vosaka-http

A powerful asynchronous HTTP library for PHP built on top of the VOsaka async runtime system. This library provides both HTTP client and server capabilities with full PSR-7 compatibility.
https://github.com/vosaka-php/vosaka-http

async-await asynchronous asynchronous-programming http-server php

Last synced: 3 months ago
JSON representation

A powerful asynchronous HTTP library for PHP built on top of the VOsaka async runtime system. This library provides both HTTP client and server capabilities with full PSR-7 compatibility.

Awesome Lists containing this project

README

          

# VOsaka HTTP

Asynchronous HTTP library for PHP with PSR-7 messages, router, middleware, HTTP client, and HTTP server.

## Features

- Async HTTP client (`Browzr`)
- Async HTTP server (`HttpServer`)
- PSR-7 message implementation
- Router with path params
- Middleware stack (CORS, favicon, custom middleware)
- Strict types, PHP 8+

## Installation

```bash
composer require venndev/vosaka-http
```

## HTTP Server (Current Flow)

`HttpServer` now runs this pipeline:

`socket -> read -> string buffer -> HTTP parser -> handler -> response builder -> string -> socket write`

This is implemented in:

- [src/vosaka/http/server/HttpServer.php](src/vosaka/http/server/HttpServer.php)

## Quick Start (Server)

```php
get('/health', function (ServerRequestInterface $req) {
return Response::json([
'status' => 'ok',
'time' => date('c'),
]);
});

$server = HttpServer::new($router)
->withDebugMode(true)
->layer(CorsMiddleware::permissive());

$server->serve('0.0.0.0:8888');
}
```

## Quick Start (Client)

```php
await();
echo $response->getStatusCode() . PHP_EOL;
```

## Local Test

```bash
php tests/server.php
```

# Benchmark
```yml
PHP ➜ ~ wrk -t12 -c1000 -d30s http://192.168.2.8:8888
Running 30s test @ http://192.168.2.8:8888
12 threads and 1000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 74.85ms 13.03ms 248.39ms 82.83%
Req/Sec 1.11k 159.39 1.64k 76.43%
397881 requests in 30.10s, 162.02MB read
Requests/sec: 13218.93
Transfer/sec: 5.38MB

NODEJS ➜ ~ wrk -t12 -c1000 -d30s http://192.168.2.8:8888
Running 30s test @ http://192.168.2.8:8888
12 threads and 1000 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 85.24ms 28.84ms 870.27ms 94.57%
Req/Sec 0.98k 186.48 1.69k 74.64%
352045 requests in 30.10s, 230.99MB read
Socket errors: connect 0, read 0, write 1558, timeout 0
Requests/sec: 11695.57
Transfer/sec: 7.67MB
```