stream ajax events, how do I handle long persistent connections?

Ryan Dahl ry at
Fri Feb 27 03:56:40 MSK 2009

> Obviously, if I just loop inside my handler callback with calls
> to sleep in between the ngx_http_output_filter calls,
> it works, but the worker process won't accept any other clients
> while it's in the loop.... I don't expect more than 30 simult
> clients/conns but don't think having 30 worker processes is the
> answer :P
> What is the proper way to do this?

You probably want to setup a timer. You do that by creating an object
of type ngx_event_t. You probably will need to set at least the
handler, log, and data fields.

The handler is a callback of type

  void (*handler)(ngx_event_t *ev)

To start the timer use

  void ngx_add_timer(ngx_event_t *ev, ngx_msec_t timer);

To stop it use

  void ngx_del_timer(ngx_event_t *ev);

Then you can check if the timer is activated by looking at ev->timer_set.

More information about the nginx mailing list