Commit f900035b273 for php.net
commit f900035b273c17c67948d89dcad76e03e885b60e
Author: David Carlier <devnexen@gmail.com>
Date: Mon Oct 20 22:42:56 2025 +0000
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 <bukka@php.net>
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