Ephemeral port exhaustion with php-fpm / mysql / nginx

On my LNMP rig I was running out of ephemeral ports even after extending the range across all registered ports in my sysctl.conf:

net.ipv4.ip_local_port_range = 1024 65000

Turns out php-fpm and mysql were both using TCP, requiring at least two connections per page request. With the TIME_WAIT minimum fixed at 60 seconds on Centos the most I could handle was about 30k page requests per minute (64k ports / 2). After setting both php-fpm (/etc/php-fpm.d/www.conf: listen = /var/run/php-fpm/default.socket) and mysql (/etc/my.conf: socket=/var/lib/mysql/mysql.sock) to use sockets and changing my php code to use them (mysql_connect(‘localhost:/var/lib/mysql/mysql.sock’,…) my ephemeral port usage is down to zero. Don’t forget to also adjust net.ipv4.ip_conntrack_max and the related timeouts to allow more connections.