Performance of unix sockets vs TCP ports

performancesockettcp

For example on php-fpm:

#listen = 127.0.0.1:9000
listen = /var/run/php-fpm/php-fpm.sock

Is there any major performance differences between using unix socket-based listeners over TCP ports? (Not just for PHP but in general. Is it different for each service?)

Best Answer

UNIX domain sockets should offer better performance than TCP sockets over loopback interface (less copying of data, fewer context switches).

Beware though that sockets are only reachable from programs that are running on the same server (there's no network support, obviously) and that the programs need to have the necessary permissions to access the socket file.

Related Question