Only fire a handler once

Aaron Bedra aaron.bedra at gmail.com
Thu Sep 5 14:22:20 UTC 2013


Thanks!


On Wed, Sep 4, 2013 at 4:38 PM, Yichun Zhang (agentzh) <agentzh at gmail.com>wrote:

> Hello!
>
> On Fri, Aug 16, 2013 at 10:28 PM, Aaron Bedra wrote:
> > I'm looking for a way to make sure a handler only fires once.
>
> If your handler is possible to run multiple times for the same request
> (like the post_subrequest handlers) and you want to avoid that, you
> can just use a module ctx field to serve as a flag for that. For
> example,
>
>     ctx = ngx_http_get_module_ctx(r, ngx_http_foo_module);
>     if (ctx == NULL) {
>         /* create ctx here and ctx->already_run should be initialized to 0
> */
>     }
>
>     if (ctx->already_run) {
>         return NGX_DONE;
>     }
>     /* first time */
>     ctx->already_run = 1;
>
>     /* process normally */
>
> Regards,
> -agentzh
>
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20130905/e6d8c50c/attachment.html>


More information about the nginx-devel mailing list