Download the PHP package makise-co/middleware without Composer
On this page you can find all versions of the php package makise-co/middleware. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download makise-co/middleware
More information about makise-co/middleware
Files in makise-co/middleware
Informations about the package middleware
PSR-15 Request dispatcher
This package provides a two high performance implementations of the PSR-15 request dispatcher
-
Dispatcher - Flat List implementation
This is a centralized architecture, the Dispatcher acts as the coordinator. Middleware receives the Dispatcher instance as the request handler. And the Dispatcher knows which next Middleware needs to be called. It works like:
- Dispatcher->handle($request) ->
- Middleware1->process($request, Dispatcher) ->
- Dispatcher->handle($request) ->
- Middleware2->process($request, Dispatcher) ->
- Dispatcher->handle($request) ->
- RequestHandler->handle($request)
-
MiddlewarePipe - Linked List implementation (harder to understand, but works a bit faster)
This is a decentralized architecture, each pipeline acts as a request handler. MiddlewarePipe is a wrapper over a middleware or a request handler. It works like:
- $pipeline->handle($request) ->
- Middleware1->process($request, $nextPipeline) ->
- $nextPipeline->handle($request) ->
- Middleware2->process($request, $nextPipeline) ->
- $nextPipeline->handle($request) ->
- RequestHandler->handle($request)
Requirements
- PHP >= 7.4
Installation
composer require makise-co/middleware
Benchmarks
10000 calls:
1 million calls:
- Laminas version used: 3.2.2
- Relay version used: 2.1.1
Benchmark code can be found here.
- Benchmarks were performed on PHP 7.4 with OPcache enabled
- CPU: Intel Core i7-9750H 6 cores (CPU frequency during benchmarks: 4.07 GHz)
- OS: Ubuntu 20.04 (WSL 2)
Usage
Dispatcher (Flat List)
MiddlewarePipe (Linked List)
Creating middleware pipeline
Each pipeline must end with Response producer, otherwise pipeline will fail with RuntimeException (Empty handler)
Merging pipelines
Execution order will be: middleware1 -> middleware1_1 -> middleware1_2 -> middleware2 -> requestHandler
Adding error handling middleware
According to the PSR-15 error handling middleware must be a first middleware in a pipeline.