tourze / proxy-protocol-core
ProxyProtocol核心定义
Installs: 118
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/tourze/proxy-protocol-core
Requires
- php: ^8.1
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-09-30 12:59:51 UTC
README
A PHP core library for parsing and generating Proxy Protocol. Supports both V1 (text format) and V2 (binary format) versions of the protocol with basic data structures and parsing capabilities.
Features
- Support for Proxy Protocol V1 (text format) and V2 (binary format)
- Enum types for safer protocol constant usage
- Complete type hints and detailed documentation
- PSR standard compliant
Installation
composer require tourze/proxy-protocol-core
Usage
Proxy Protocol V1
use Tourze\ProxyProtocol\Enum\Version; use Tourze\ProxyProtocol\Model\Address; use Tourze\ProxyProtocol\Model\V1Header; // Create a V1 header $header = new V1Header(); $header->setVersion(Version::V1); $header->setProtocol('TCP4'); $header->setSourceAddress(new Address('192.168.1.1', 12345)); $header->setTargetAddress(new Address('192.168.1.2', 80));
Proxy Protocol V2
use Tourze\ProxyProtocol\Enum\AddressFamily; use Tourze\ProxyProtocol\Enum\Command; use Tourze\ProxyProtocol\Enum\Version; use Tourze\ProxyProtocol\Model\V2Header; // Create a V2 header $header = new V2Header(); $header->setVersion(Version::V2); $header->setCommand(Command::PROXY); $header->setAddressFamily(AddressFamily::TCP4); $header->setSourceAddress('192.168.1.1'); $header->setSourcePort(12345); $header->setTargetAddress('192.168.1.2'); $header->setTargetPort(80); // Parse a V2 header $data = "..."; // Binary data containing Proxy Protocol V2 header $header = V2Header::parseHeader($data);