Home  >  Q&A  >  body text

Is fastcgi_pass in nginx set to monitor unix socket more efficient than monitoring tcp socket?

I saw that fastcgi_pass in other people’s nginx configuration is unix:/tmp/php-cgi.sock

But my configuration is 127.0.0.1:9000 (not talking about load balancing, just the simplest oneserver)

What is the difference between

unix:/tmp/php-cgi.sock and 127.0.0.1:9000?

Is the former processing faster?

I see in my php-fpm.conf

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses on a
;                            specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 127.0.0.1:9000

Should you change the configuration of listen to /tmp/php-cgi.sock?

漂亮男人漂亮男人2712 days ago721

reply all(2)I'll reply

  • 怪我咯

    怪我咯2017-05-16 17:28:00

    Well, unix socket will be faster and does not use the network
    In addition, it is better to put it in the /tmp directory than to put it in the memory
    I usually put it in /dev/shm/php-fpm.sock
    Put it in the memory and read it faster

    reply
    0
  • PHPz

    PHPz2017-05-16 17:28:00

    Theoretically, unix socket will be faster if it does not go through the network,
    However, the stability is not so ideal,
    Someone has done the test here, you can refer to it
    http://blog.csdn.net/liv2005/article/details/7741732

    reply
    0
  • Cancelreply