Skip to content

Commit 98b9c4f

Browse files
devnexenbukka
andcommitted
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>
1 parent aead67d commit 98b9c4f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

main/network.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,13 @@ php_socket_t php_network_bind_socket_to_local_addr(const char *host, unsigned po
497497
/* attempt to bind */
498498

499499
if (sockopts & STREAM_SOCKOP_SO_REUSEADDR) {
500+
#ifdef SO_REUSEPORT_LB
501+
/* Historically, SO_REUSEPORT on FreeBSD predates Linux version, however does not
502+
* involve load balancing grouping thus SO_REUSEPORT_LB is the genuine equivalent.*/
503+
setsockopt(sock, SOL_SOCKET, SO_REUSEPORT_LB, (char*)&sockoptval, sizeof(sockoptval));
504+
#else
500505
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*)&sockoptval, sizeof(sockoptval));
506+
#endif
501507
}
502508
#ifdef PHP_WIN32
503509
else {

0 commit comments

Comments
 (0)