From 23cd1193ce18f702e10c812e96b1cb03975561a2 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Mon, 20 Oct 2025 22:42:56 +0000 Subject: [PATCH] network: on freebsd using SO_REUSEPORT_LB for a better distribution. SO_REUSEPORT on FreeBSD acts differently as the underlying semantic is different (as it predates Linux) since it s more for UDP/multicasts. The SO_REUSEPORT_LB flag, however, uses load balancing for group of address:port combinations which is how Linux is implemented. --- main/network.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main/network.c b/main/network.c index 7be64c2c4e1f1..2f38f86ba1181 100644 --- a/main/network.c +++ b/main/network.c @@ -87,6 +87,14 @@ const struct in6_addr in6addr_any = {0}; /* IN6ADDR_ANY_INIT; */ # define PHP_TIMEOUT_ERROR_VALUE ETIMEDOUT #endif +#ifdef SO_REUSEPORT_LB +// Historically, SO_REUSEPORT on FreeBSD predates Linux version +// however does not involve load balancing grouping thus +// SO_REUSEPORT_LB is the genuine equivalent. +# undef SO_REUSEPORT +# define SO_REUSEPORT SO_REUSEPORT_LB +#endif + #ifdef HAVE_GETADDRINFO # if !defined(PHP_WIN32) && !defined(HAVE_GAI_STRERROR) /* {{{ php_gai_strerror */