Download the PHP package tourze/load-balancer without Composer

On this page you can find all versions of the php package tourze/load-balancer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package load-balancer

Generic Load Balancer

中文

一个通用的、与框架无关的 PHP 负载均衡库。它提供了多种负载均衡策略,以满足从简单轮询到复杂动态负载分配的各种需求。

该库的核心设计原则是简单、灵活和可扩展。

特性

安装

通过 Composer 安装:

如果你计划使用 CacheStateProvider,请确保你的项目已经依赖了一个实现 psr/cache 的库(例如 symfony/cache)。

使用方法

快速开始

使用 LoadBalancerFactory 是最简单的入门方式。

节点 (Node)

Node 对象是所有负载均衡策略的基本单元。


可用策略

1. 随机策略 (RandomBalancer)

从节点列表中完全随机地选择一个。

2. 轮询策略 (RoundRobinBalancer)

按顺序逐个选择节点。这是一个有状态的策略。

3. 加权随机策略 (WeightedBalancer)

根据节点的权重进行随机选择,权重越高的节点被选中的概率越大。

4. IP 哈希策略 (IpHashBalancer)

确保来自同一个 IP 地址的请求总是被分配到同一个节点。非常适合用于实现会话保持。

5. 最少连接数策略 (LeastConnectionsBalancer)

选择当前活动连接数最少的节点。这是一个动态策略,需要外部逻辑来更新连接数。

6. 平滑加权轮询策略 (SmoothWeightedRoundRobinBalancer)

Nginx 使用的平滑加权算法。它能确保请求分发平滑,避免在短时间内集中请求高权重节点。

对于权重为 {A:5, B:1, C:1} 的节点,7次请求的序列将是 A, A, B, A, C, A, A,分布非常均匀。


状态管理

对于有状态的策略(如 RoundRobinBalancer, LeastConnectionsBalancer),你可以通过注入一个 StateProviderInterface 的实现来控制状态的存储。

InMemoryStateProvider (默认)

状态仅在当前 PHP 进程的生命周期内有效。无需任何配置。

ApcuStateProvider (单机跨进程)

如果你的环境安装并启用了 APCu 扩展,可以使用它在同一台服务器的多个进程间共享状态。

CacheStateProvider (分布式)

这是最灵活的方式,可以对接任何实现了 PSR-6 (Psr\Cache\CacheItemPoolInterface) 的缓存系统,如 Redis、Memcached 等。

示例:使用 Symfony Cache 对接 Redis

贡献

欢迎提交 PR 和 issue!


All versions of load-balancer with dependencies

PHP Build Version
Package Version
Requires composer-runtime-api Version ^2.0
psr/cache Version ^2.0 || ^3.0
symfony/cache Version ^7.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package tourze/load-balancer contains the following files

Loading the files please wait ...