Hello,
I have a question concerning HAProxy load balancing via php curl
requests using three Omnis servers as destination, and I hope there is
someone who might be able to get me on the right track, because I'm a
little lost at the moment.
How things are running initially and working:
- our Nginx/PHP server makes a php curl_setopt() request to our Omnis
server which sends back data to be processed accordingly.
Our goal:
- use HAProxy for load balancing these requests to multiple Omnis
servers (since Omnis can only process sequentially, causing queueing of
incoming requests).
What is working:
- The load balance setup with three servers when using "mode http" and
accessing the end point directly through a URL in the webbrowser
(bypassing the php curl call): [http://192.168.0.131:9000 (HAProxy
server)](http://192.168.0.131:9000), this goes to each Omnis server as
intended.
- the config that is working:
defaults
mode http
stats enable
timeout connect 5s
timeout client 1m
timeout server 1m
frontend stats
bind *:9900
mode http
stats enable
stats uri /stats
stats refresh 10s
stats admin if LOCALHOST
frontend public
bind *:9000
mode http
stats enable
default_backend public_backend
backend public_backend
mode http
stats enable
balance roundrobin
timeout server 300s
server web01 192.168.0.10:80 check
server web02 192.168.0.11:80 check
server web03 192.168.0.12:80 check
What isn't working:
- the php curl_setopt() request when using "mode http" (application
layer) doesn't work, HAProxy doesn't seem to receive the request.
I've found out that using "mode tcp" (transport layer) works, but it
load balances a little too much (sessions go over the three servers and
thus doesn't keep its session).
Setting "stick-table type ip size 1m expire 30m" and "stick on src"
doesn't pay off since the source IP is always the same (our nginx/php
server) causing not to load balance anymore.
I tried to inject a PHPSESSID parameter in php, containing the "session
id" into the header. This is captured on our Omnis server using a direct
connection (ex. PHPSESSID=75lnpdmtil3q87ogt317n86kjh -> 26 characters),
but I can't seem to capture this in the HAProxy config.
The tcplog doesn't show much except for whether it load balances or
not: "192.168.0.131 local0 haproxy 192.168.0.61:61143
[26/Mar/2025:15:35:35.935] public public_backend/web01 1/6/110 95 --
1/1/0/0/0 0/0"
My question(s):
- how can I capture the PHPSESSID in the HAProxy config?
- maybe out of the scope of HAProxy: is there a way to use "mode http"
with the curl_setopt() php function?
My latest config so far (note that lines starting with # are some of the
things I've tried):
global
log 192.168.0.37:514 local0 info
defaults
log global
option tcplog
timeout connect 5s
timeout client 1m
timeout server 1m
frontend stats
bind *:9900
mode http
stats enable
stats uri /stats
stats refresh 10s
stats admin if LOCALHOST
frontend public
bind *:9000
mode tcp
default_backend public_backend
# tcp-request inspect-delay 5s
# stick-table type string size 200k expire 30m store conn_cur
# tcp-request content capture req.payload(0,100) len 100
# tcp-request content accept if { req.payload(0,100) -m found
"PHPSESSID=" }
# tcp-request content track-sc0 req.payload(0,100)
# use_backend public_backend if { req.payload(0,100) -m found
"PHPSESSID=" }
backend public_backend
mode tcp
balance roundrobin
# stick-table type ip size 1m expire 30m
# stick on src
# tcp-request inspect-delay 5s
# stick-table type string size 200k expire 30m store conn_cur
# tcp-request content capture req.payload(0,100) len 100
# tcp-request content accept if { req.payload(0,100) -m found
"PHPSESSID=" }
# tcp-request content track-sc0 req.payload(0,100)
#stick-table type binary len 25 size 1m expire 1h
#stick on req.payload(0,25)
#tcp-request inspect-delay 2s
#tcp-request content accept if WAIT_END
# stick-table type ip size 200k expire 30m store conn_cur
# stick on src
# cookie PHPSESSID prefix nocache
# stick-table type string len 32 size 100k expire 30m
# stick on req.cook(sessionid)
#stick-table type string size 200k expire 30m
#stick on req.payload(0,26)
server web01 192.168.0.10:5912 check
server web02 192.168.0.11:5913 check
server web03 192.168.0.12:5914 check
Any help would be appreciated.
Thank you for your time!
Kind regard,
Dimitri