@@ -17,7 +17,7 @@ decisions.
1717## Features
1818
1919* Native SPOE protocol implementation
20- * Event-driven, non-blocking I/O using ReactPHP
20+ * Event-driven, asynchronous I/O using ReactPHP
2121* Simple handler-based programming model
2222* Support for all HAProxy variable scopes
2323* Minimal runtime dependencies
@@ -62,7 +62,8 @@ The central abstraction in this framework is `SPOA\Server\Connection`.
6262
6363Each incoming SPOE connection from HAProxy is represented by a
6464` Connection ` instance. Applications register message handlers on the
65- connection and return variables to HAProxy in response.
65+ connection and return variables (or Promises that resolve to variables)
66+ to HAProxy in response.
6667
6768The framework handles:
6869
@@ -80,7 +81,7 @@ Your application code only needs to define handlers.
8081Handlers are registered by message name:
8182
8283``` php
83- $conn->on('get-ip-reputation', function (array $args) {
84+ $conn->on('get-ip-reputation', function (array $args): PromiseInterface|array {
8485 // ...
8586});
8687```
@@ -90,7 +91,7 @@ $conn->on('get-ip-reputation', function (array $args) {
9091 configuration.
9192
9293* ** Arguments (** ` $args ` ** )** : An associative array of
93- ` SPOA\Protocol\Arg ` objects .
94+ ` SPOA\Protocol\Arg ` object instances .
9495
9596 * ** Named Arguments** : Accessed via their name defined in HAProxy
9697 (e.g., ` $args['client_ip'] ` ).
@@ -152,6 +153,7 @@ programming model.
152153``` php
153154<?php
154155use React\EventLoop\Loop;
156+ use React\Promise\PromiseInterface;
155157use React\Socket\Server;
156158
157159use SPOA\Protocol\Arg;
@@ -164,7 +166,7 @@ $server = new Server('127.0.0.1:12345', $loop);
164166$server->on('connection', function ($conn) {
165167 $spoa = new Connection($conn);
166168
167- $spoa->on('get-ip-reputation', function (array $args): array {
169+ $spoa->on('get-ip-reputation', function (array $args): PromiseInterface| array {
168170 $srcIp = $args['ip']?->value;
169171
170172 // check IP address and set reputation
@@ -194,21 +196,19 @@ The application runs inside a standard ReactPHP event loop.
194196### SPOE configuration (` spoe-test.cfg ` )
195197
196198``` cfg
197- [spoe-test]
198-
199199spoe-agent iprep-agent
200200 messages get-ip-reputation
201201 option var-prefix iprep
202202
203- timeout hello 2s
204- timeout idle 2m
205- timeout processing 10ms
203+ timeout hello 200ms
204+ timeout idle 10m
205+ timeout processing 500ms
206206
207207 use-backend iprep-server
208208
209209spoe-message get-ip-reputation
210210 args ip=src
211- event on-client-session
211+ event on-frontend-http-request
212212```
213213
214214---
@@ -217,8 +217,8 @@ spoe-message get-ip-reputation
217217
218218``` cfg
219219frontend http
220- filter spoe engine spoe-test config /etc/haproxy/spoe-test.cfg
221- http-request set-header X-Test 1 if { var(sess.iprep.score) -m int gt 20 }
220+ filter spoe config /etc/haproxy/spoe-test.cfg
221+ http-request set-header X-Pass 1 if { var(sess.iprep.score) -m int gt 20 }
222222
223223backend iprep-server
224224 mode tcp
0 commit comments