About this article
This article is created using an automated generation workflow utilizing generative AI. Based on Linux Unix domain socket documentation and TCP specifications, it outlines a procedure to observe the true nature of.sockusing only a temporary directory, without touching production PHP-FPM sockets.
Verification Status: 📘 Official information verified, local execution unverified
The .sock entries found in Nginx and PHP-FPM configurations are not necessarily standard configuration files. Unix domain sockets are sockets that can be used for inter-process communication within the same host, and pathname sockets use a path on the file system as a name instead of an IP address and port.
- Get It Running
- man7.org — unix(7)
- You can observe that the initial file type differs from a regular file. Although the path is visible on the filesystem, it is not treated as a standard text file for storing content.
- While Unix sockets may be used in configurations communicating exclusively within the same host, do not simplify by assuming they are "always faster than TCP" or "always the right choice." Operations, permissions, and container boundaries are also design factors.
- . This reconfirms that the name is a path, not an IP/port.
- Because abnormal process termination can leave the socket path behind, production systems must be designed to handle cleanup before startup and upon termination.
- serves as the communication endpoint.
- Verify path-sharing prerequisites in containers or cross-host communication
- man7.org — unix(7)
Get It Running
Do not touch production /run/php/*.sock./tmp Use a dedicated temporary directory for
with only the Python standard library.
TMPDIR="$(mktemp -d)"
SOCK="$TMPDIR/demo.sock"
export SOCK
echo "[START] socket path=$SOCK"
python3 - <<'PY'
import os, socket
path = os.environ['SOCK']
server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
server.bind(path)
server.listen(1)
print('[LISTEN]', path, flush=True)
conn, _ = server.accept()
data = conn.recv(1024)
print('[RESULT] recv =', data.decode(), flush=True)
conn.sendall(b'ACK_UNIX')
conn.close()
server.close()
print('[SUCCESS] server finished', flush=True)
PY
[LISTEN]Terminal 1:SOCK Once output appears, connect from Terminal 2. Insert the path displayed in Terminal 1 into
export SOCK='/tmp/表示されたディレクトリ/demo.sock'
python3 - <<'PY'
import os, socket
client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
client.connect(os.environ['SOCK'])
client.sendall(b'HELLO_UNIX')
print('[RESULT]', client.recv(1024).decode())
client.close()
PY
.unix(7)Linux Unix domain sockets are described in
man7.org — unix(7)
Check this
ls -l "$SOCK"
Verify from another terminal while the server is listening.
flowchart LR
C[Client process] --> U[Unix domain socket path]
U --> S[Server process]
C -. IP/portを使わない .-> S
You can observe that the initial file type differs from a regular file. Although the path is visible on the filesystem, it is not treated as a standard text file for storing content.
How is it different from TCP localhost?127.0.0.1:9000With TCP, communication endpoints are typically represented by an IP address and port, such as [::1]:9000 or /run/php/php-fpm.sock. With pathname Unix sockets, a path like
serves as the communication endpoint.
RFC Editor — RFC 9293 Transmission Control Protocol
While Unix sockets may be used in configurations communicating exclusively within the same host, do not simplify by assuming they are "always faster than TCP" or "always the right choice." Operations, permissions, and container boundaries are also design factors.
Change One Thingdemo.sockChange only the socket path name from app.sock to
SOCK="$TMPDIR/app.sock"
. This reconfirms that the name is a path, not an IP/port.
Cleanup
rm -f "$SOCK" rmdir "$TMPDIR" 2>/dev/null || true echo '[CLEANUP] temporary socket removed'
Remove the temporary socket and directory after the server shuts down.
Because abnormal process termination can leave the socket path behind, production systems must be designed to handle cleanup before startup and upon termination.
What should I check in PHP-FPM?listenThere are configurations where the PHP-FPM
points to a pathname socket, and the Nginx FastCGI configuration points to the same socket. When troubleshooting, examine the following separately:
Whether the socket path exists
Owner, group, and mode
Whether the PHP-FPM process is listening
Whether Nginx is referencing the same path
Do not delete production sockets for testing purposes.sockThis demo does not alter production settings; it solely reproduces the aspect where
serves as the communication endpoint.
/runBest Practices for Production UseNever arbitrarily delete production
sockets
Avoid recklessly setting socket permissions to 777
Verify the service user and group
Verify path-sharing prerequisites in containers or cross-host communication
man7.org — unix(7)
RFC Editor — RFC 9293.sockConclusionlsPathname Unix domain sockets allow communication partners on the same host to be represented by a path on the filesystem. By creating a temporary
