From f900035b273c17c67948d89dcad76e03e885b60e 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. Co-authored-by: Jakub Zelenka --- main/network.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main/network.c b/main/network.c index 0dadf0bb4dc..6c43321cf2e 100644 --- a/main/network.c +++ b/main/network.c @@ -512,7 +512,13 @@ php_socket_t php_network_bind_socket_to_local_addr(const char *host, unsigned po #endif #ifdef SO_REUSEPORT if (sockopts & STREAM_SOCKOP_SO_REUSEPORT) { +# 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.*/ + setsockopt(sock, SOL_SOCKET, SO_REUSEPORT_LB, (char*)&sockoptval, sizeof(sockoptval)); +# else setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (char*)&sockoptval, sizeof(sockoptval)); +# endif } #endif #ifdef SO_BROADCAST