Download the PHP package 52-entertainment/302 without Composer
On this page you can find all versions of the php package 52-entertainment/302. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download 52-entertainment/302
More information about 52-entertainment/302
Files in 52-entertainment/302
Package 302
Short Description A redirect balancer between several hosts.
License MIT
Informations about the package 302
302
This is a load balancer that doesn't act as a load balancer.
It is a redirect balancer. Instead of forwarding traffic to a specific host/port, it returns a 302 response with a different location.
Typical usage is that your entrypoint is https://example.com/foo
and you want to redirect your traffic
to a pool made of https://01.example.com
and https://02.example.com
, by keeping path and query string intact.
It is built with PHP 8 on top of ReactPHP. Because it answers very short responses and runs within a loop, it can easily handle thousands of requests/s without blinking an eye.
Build
Build is optional (you can simply run php bin/console serve
) but will produce an optimized, single-file executable PHAR.
PHP 8, Composer and Box are globally required on your computer.
To build the application, run:
It will land in bin/302
.
Usage
Live balancing (no persistence - for testing purposes or prototyping)
Persisted storage (Redis)
App will run, but user agent will get 503 errors because the server pool is empty.
Add a server to the pool
This command can be run while 302 serve
is running, no need to restart the app!
Remove a server from the pool
This command can be run while 302 serve
command is running, no need to restart the app!
List servers in the pool
Tests
Deployment
Example Supervisor config
After building the app, you can easily create a supervisor recipe to load it on startup:
With the above config, 302 will run on 127.0.0.1:8000
, 127.0.0.1:8001
, 127.0.0.1:8002
and 127.0.0.1:8003
.
Round-robin will be shared across the instances (since they share the same Redis instance).
CORS / SSL termination
302 has no built-in CORS nor SSL termination, but this can be handled by any web server with reverse-proxy capabilities (Apache, Nginx, Caddy, ...).
Caddyfile example
If you're using Caddy, here's an example Caddyfile
:
All versions of 302 with dependencies
ext-ctype Version *
ext-iconv Version *
ext-pcntl Version *
ext-redis Version *
bentools/uri-factory Version ^2.2
clue/redis-react Version ^2.4
nyholm/dsn Version ^2.0
react/http Version ^1.2
symfony/console Version 5.2.*
symfony/dotenv Version 5.2.*
symfony/flex Version ^1.3.1
symfony/framework-bundle Version 5.2.*
symfony/yaml Version 5.2.*