# 回复： Re: How to

**URL:** <https://www.ruby-forum.com/t/re-how-to/225662>\
**Category:** NGINX\
**Created:** [January 22, 2013, 2:34pm UTC](https://www.ruby-forum.com/t/re-how-to/225662 "2013-01-22T14:34:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [January 22, 2013, 2:34pm UTC](https://www.ruby-forum.com/t/re-how-to/225662/1 "2013-01-22T14:34:18Z")

</div>

=?UTF-8?Q?bind\_variable\_with?=

=?UTF-8?Q?\_connection\_in\_a\_customized\_module=3F?=  
MIME-Version: 1.0  
Content-Type: text/plain; charset=“utf-8”  
Content-Transfer-Encoding: quoted-printable

Thank you very much. And for your note, I know the connections are  
reusable=  
, it’s not a problem for me. To be sure, during a client is alive, the  
conn=  
ection won’t serve other clients, is it correct?

Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)=E7=BC=96=E5=86=99=EF=BC=9A

Hello!

On Tue, Jan 22, 2013 at 08:16:36PM +0800, Liu H. wrote:

> hi all,  
> =20  
> I want save state during a long connection (keep-alive) for=20  
> performance optimization in my own HTTP handler module, thus I=20  
> can peek up the saved state when handling requests, to speed up=20  
> response. Actually it’s quite like session concept. I saw=20  
> request struct has a member ctx, but what I want is a ctx on the=20  
> connection. It seems no way to save any customized variable to=20  
> the ngx\_connection\_t structure. What’s the suggested way to make=20  
> this if I don’t want the client hold something like session\_id?

This was recently discussed on nginx-devel@ mailing list, and=20  
probably the best way currently available is to install connection=20  
pool cleanup handler with custom data and then iterate over=20  
connection pool cleanup handlers to find your data. It is=20  
relatively costly, but allows to keep memory footprint from=20  
keepalive connections low and still allows modules to keep their=20  
per-connection data in rare cases when they really need to.

See here:  
[http://mailman.nginx.org/pipermail/nginx-devel/2012-December/003049.html](http://mailman.nginx.org/pipermail/nginx-devel/2012-December/003049.html)

Note well though, that HTTP is stateless protocol, and the fact=20  
that request came from the same connection means mostly nothing:=20  
it might be a request from a completely different user.

–=20  
Maxim D.

> **[Technical Support for NGINX and NGINX Plus Software](https://www.nginx.com/support/)**
>
> Get the help you need with support directly from the authors and maintainers of NGINX Open Source and NGINX Plus.

* * *

nginx mailing list  
removed\_email\_address@domain.invalid  
[http://mailman.nginx.org/mailman/listinfo/nginx](http://mailman.nginx.org/mailman/listinfo/nginx)

---

<div class="post-metadata">

**Author:** ![Haifeng\_Liu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/7cd45c/32.png) [@Haifeng\_Liu](https://www.ruby-forum.com/u/Haifeng_Liu)\
**Post date:** [January 22, 2013, 3:16pm UTC](https://www.ruby-forum.com/t/re-how-to/225662/2 "2013-01-22T15:16:56Z")

</div>

Hello!

(Just a side note: it looks like you mail client have problems  
with proper mail encoding. I have to recover message headers by  
hand, as the Subject header was split across multiple  
non-consecutive lines, breaking other headers as well.)

On Tue, Jan 22, 2013 at 05:33:31AM -0800, Haifeng Liu wrote:

> Thank you very much. And for your note, I know the connections  
> are reusable, it’s not a problem for me. To be sure, during a  
> client is alive, the connection won’t serve other clients, is it  
> correct?

This depends on what do you mean by “client”. If next hop http  
client - true, the connection is always with one client. But on  
the same connection request from different users might appear,  
e.g. if requests are proxied via the same proxy server (“client”  
from nginx point of view).

It might be helpfull to read this section of RFC2616 for better  
understanding:

> **[RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1 | RFC Editor](https://www.rfc-editor.org/info/rfc2616/)**
>
> HTTP has been in use by the World-Wide Web global information initiative since 1990. This specification defines the protocol referred to as "HTTP/1.1", and is an update to RFC 2068. \[STANDARDS-TRACK\]

> > I want save state during a long connection (keep-alive) for  
> > pool cleanup handler with custom data and then iterate over  
> > it might be a request from a completely different user.
> 
> –  
> Maxim D.  
> [NGINX | F5](http://nginx.com/support.html)
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

–  
Maxim D.

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.

---

<div class="post-metadata">

**Author:** ![Haifeng\_Liu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/7cd45c/32.png) [@Haifeng\_Liu](https://www.ruby-forum.com/u/Haifeng_Liu)\
**Post date:** [January 23, 2013, 5:03am UTC](https://www.ruby-forum.com/t/re-how-to/225662/3 "2013-01-23T05:03:37Z")

</div>

Thank you again. Last mail was sent from my mobile phone(android). Sorry  
for the trouble.

Proxied connection is not a big problem for me for now. But good note,  
I’ll think about it in the future.
