微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

通过fast-cgi连接php-fpm和nginx之间的连接是持久的(保持活动)连接吗?

我正在尝试编写一个服务器演示来连接PHP-fpm,但我不知道PHP-fpm和Nginx间的连接是否是fast-cgi是持久的(保持活动)连接?
每当http请求到Nginx时,Nginx会再次通过tcp 3-Way Handshake连接PHP-fpm吗?或者NginxPHP-fpm之间的连接是一个keep-alive连接,而Nginx尝试重用它?

解决方法:

PHP-FPM是fastCGI协议的一种实现,因此它遵守所有fastCGI规范要求.

其中一个要求是在section 3.5 of the specification中,特别是关于关闭连接:

The Web server controls the lifetime of transport connections. The Web server can close a connection when no requests are active. Or the Web server can delegate close authority to the application (see FCGI_BEGIN_REQUEST). In this case the application closes the connection at the end of a specified request.
This flexibility accommodates a variety of application styles. Simple applications will process one request at a time and accept a new transport connection for each request. More complex applications will process concurrent requests, over one or multiple transport connections, and will keep transport connections open for long periods of time.

A simple application gets a significant performance boost by closing the transport connection when it has finished writing its response. The Web server needs to control the connection lifetime for long-lived connections.

When an application closes a connection or finds that a connection has closed, the application initiates a new connection.

这意味着由Web服务器决定连接是否会持续存在.这是通过fastcgi_keep_conn选项在Nginx中实现的,该选项指出:

By default, a FastCGI server will close a connection right after sending the response. However, when this directive is set to the value on, Nginx will instruct a FastCGI server to keep connections open. This is necessary, in particular, for keepalive connections to FastCGI servers to function.

此语句用于反映规范行为以及可以为fastCGI生成内容提供服务以修改认行为的Web服务器的功能.

我的假设是,由于网络服务器的线程不断被回收,因此保持连接不存在真正的意义.也许有一定数量的停放线程,但通常的线程池策略是杀死least recently used线程,通常这意味着产生一个新线程将确保预先退出的线程被杀死.

不可否认,我没有找到任何资源来支持Nginx的池收集策略是LRU的说法,但它不是不可能的,在这种情况下保持连接存活不会节省太多.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐