Not really a load balancer.

Overview

CI Workflow Codecov

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:

./bin/build

It will land in bin/302.

Usage

Live balancing (no persistence - for testing purposes or prototyping)

php bin/302 serve \
--host=0.0.0.0 \
--port=8080 \
--pick=random \ # or round-robin
example1.org \
example2.org \
example3.org
GET http://0.0.0.0:8080/foo?bar=baz

HTTP/1.1 302 Found 
Location: http://example2.org/foo?bar=baz

Persisted storage (Redis)

# Expose the REDIS_DSN variable if necessary, default is:
export REDIS_DSN="redis://localhost:6379"
php bin/302 serve --host=0.0.0.0 --port=8080

App will run, but user agent will get 503 errors because the server pool is empty.

Add a server to the pool

php bin/302 server:add example1.org

This command can be run while 302 serve is running, no need to restart the app!

Remove a server from the pool

php bin/302 server:remove example1.org

This command can be run while 302 serve command is running, no need to restart the app!

List servers in the pool

php bin/302 server:list

Tests

./vendor/bin/pest

Deployment

Example Supervisor config

After building the app, you can easily create a supervisor recipe to load it on startup:

[program:302]
command=php /usr/local/bin/302 serve --host=127.0.0.1 --port=80%(process_num)02d
user=www-data
numprocs=4
startsecs=1
autostart=true
autorestart=true
process_name=%(program_name)s_%(process_num)02d
environment = APP_LOG_DIR=/var/log/302

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:

example.org {
    @get {
        method GET
    }
    @options {
        method OPTIONS
    }
    header Access-Control-Allow-Origin *
    header Access-Control-Allow-Redirect true
    respond @options 200
    reverse_proxy @get 127.0.0.1:8000 127.0.0.1:8001 127.0.0.1:8002 127.0.0.1:8003
}
You might also like...
The fixture plugin is really helpful if you want to create some static demo data for your shopware instance.

Fixture Plugin The fixture plugin is really helpful if you want to create some static demo data for your shopware instance. Installation Just add it t

Laravel Proxy Package for handling sessions when behind load balancers or other intermediaries.

Laravel Trusted Proxies Setting a trusted proxy allows for correct URL generation, redirecting, session handling and logging in Laravel when behind a

MySQL Load Data Infile Support For Laravel

Laravel Load File 💽 A package to help with loading files into MySQL tables. This uses MySQL's LOAD DATA statement to load text files quickly into you

Laravel Typical High-Load Example.
Laravel Typical High-Load Example.

Laravel Typical High-Load Example 淺談基於 Laravel 框架的高流量、高併發網路應用架構的設計與效能優化。 摘要 網際網路的服務推陳出新,使用者的習性也不斷變化,使得網路應用服務必須面對極端的需求,例如電子商務中常見的商品限時、限量、促銷搶購或是演唱會搶票等,這

The game is implemented as an example of scalable and high load architecture combined with modern software development practices
The game is implemented as an example of scalable and high load architecture combined with modern software development practices

Crossword game The game is implemented as an example of scalable and high load architecture combined with modern software development practices Exampl

Load files and classes as lazy collections in Laravel.

Lody Load files and classes as lazy collections in Laravel. Installation composer require lorisleiva/lody Usage Lody enables you to fetch all exist

Framework agnostic package to load heavy JSON in lazy collections.

Lazy JSON Framework agnostic package to load heavy JSON in lazy collections. Under the hood, the brilliant JSON Machine by @halaxa is used as lexer an

🐼 Framework agnostic package using asynchronous HTTP requests and PHP generators to load paginated items of JSON APIs into Laravel lazy collections.

Framework agnostic package using asynchronous HTTP requests and generators to load paginated items of JSON APIs into Laravel lazy collections.

Helper to automatically load various Kirby extensions in a plugin

Autoloader for Kirby Helper to automatically load various Kirby extensions in a plugin Commerical Usage This package is free but if you use it in a co

Automatically load your helpers in your laravel application.

Laravel AutoHelpers Automatically load your helpers in your laravel application. Installation You can install the package via composer: composer requi

LOAD is a PHP library for configuration loading to APCu

LOAD LOAD is a PHP library for configuration loading to APCu Sources Available sources for configuration loading are: PHP file Consul Environment vari

Load head metadata from a manifest file which can be shared with a SPA project

Laravel Head Manifest Installation Step 1: Add Laravel Head Manifest to your laravel project composer require critiq/laravel-head-manifest Step 2: Add

 Load Laravel service providers based on your application's environment.
Load Laravel service providers based on your application's environment.

Laravel EnvProviders A more finetuned way of managing your service providers in Laravel. This package allows you to configure the environment certain

Load-Balance PaperCut ETP Print Queues using Postfix

ETP Load Balancing for PaperCut using Postfix This script is designed to allow you to load balance a single Email-To-Print address against multiple pr

Plugin for Kirby that allows you to load assets generated by Vite.

Kirby Vite Plugin Plugin for Kirby that allows you to load assets generated by Vite. In development mode, assets are loaded from Vite's development se

 Lazyline - Innovative Lazy-Load & LQIP WordPress Plugin
Lazyline - Innovative Lazy-Load & LQIP WordPress Plugin

Multifunctional WordPress image-optimization plugin. Provides many lazy-load features (backgrounds, video, sources, iframes, scripts, hidpi, webp), full LQIP support (thumbnails, color palette, pixelart, primitives), and additional image optimization/validation options.

Simple way to auto load modules without complicate definition of routes

Phalcon-autorouter Version 2.0 Example full application with various libraries included in this example Change log Structure have been changed and upd

Laravel package to search through multiple Eloquent models. Supports sorting, pagination, scoped queries, eager load relationships and searching through single or multiple columns.

Laravel Cross Eloquent Search This Laravel package allows you to search through multiple Eloquent models. It supports sorting, pagination, scoped quer

Automatically load the next page of products in Magento. Easy to install and configure, this module works 100% out of the box with vanilla Magento 1.9.x and earlier.

Automatically load the next page of products in Magento. Easy to install and configure, this module works 100% out of the box with vanilla Magento 1.9.x and earlier.

Releases(1.0)
Owner
52 Entertainment
52 Entertainment
💾 High-performance PHP application server, load-balancer and process manager written in Golang. RR2 releases repository.

RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a serv

Spiral Scout 45 Nov 29, 2022
🤯 High-performance PHP application server, load-balancer and process manager written in Golang

RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a serv

Spiral Scout 6.9k Jan 3, 2023
Framework agnostic package to load heavy JSON in lazy collections.

Lazy JSON Framework agnostic package to load heavy JSON in lazy collections. Under the hood, the brilliant JSON Machine by @halaxa is used as lexer an

Andrea Marco Sartori 155 Dec 1, 2022
RRR makes structured data for WordPress really rich, and really easy.

Really Rich Results - JSON-LD Structured Data (Google Rich Results) for WordPress Search engines are putting more weight on structured data than ever

Pagely 22 Dec 1, 2022
PPM is a process manager, supercharger and load balancer for modern PHP applications.

PPM - PHP Process Manager PHP-PM is a process manager, supercharger and load balancer for PHP applications. It's based on ReactPHP and works best with

PPM - PHP Process Manager 6.5k Jan 3, 2023
PPM is a process manager, supercharger and load balancer for modern PHP applications.

PPM - PHP Process Manager PHP-PM is a process manager, supercharger and load balancer for PHP applications. It's based on ReactPHP and works best with

PPM - PHP Process Manager 6.5k Dec 27, 2022
💾 High-performance PHP application server, load-balancer and process manager written in Golang. RR2 releases repository.

RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a serv

Spiral Scout 45 Nov 29, 2022
🤯 High-performance PHP application server, load-balancer and process manager written in Golang

RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a serv

Spiral Scout 6.9k Jan 3, 2023