custom handler module - dynamic response with unknown content length

Yasser Zamani yasser.zamani at
Sat Mar 1 14:57:38 UTC 2014

On Sat 01 Mar 2014 03:01:42 PM IRST, Maxim Dounin wrote:
> Hello!
> The ngx_http_output_filter() function can be called more than
> once, but usually it doesn't make sense - instead, one should
> install r->write_event_handler and do subsequent calls once it's
> possible to write additional data to socket buffer.  Working with
> event's isn't something trivial though.

Thanks a lot for write_event_handler.

> Quoting Winnie-the-Pooh, "You needn't shout so loud".
> Doing time-consuming transcoding in nginx worker isn't correct in
> any case, as it will block all connections in this worker process.
> So you have to do transcoding in some external process, and talk
> to this process to get transcoded data.  This is basically what
> upstream module do (as used by proxy, fastcgi, etc.), and it
> can be used as an example of "how to do this in nginx".

The transcoding process already is doing by an external process, 
ffmpeg, into an incomplete file. I just need to read from first of this 
incomplete file one by one chunks and send them to client until seeing 
a real EOF. I have following plan for nginx configuration:
location \*.mp4 { mymodule; }

So, did you mean if two clients get x.mp4 and y.mp4 in same time then 
one of them is blocked until another one get complete file?! I don't 
think so while web servers usually make new threads.

I saw './nginx-1.4.5/src/http/ngx_http_upstream.c' but was so complex 
for me to understand.

However, I saw FastCGI is simple for me to understand. So, do you 
advise me to `regularly read ffmpeg output file` in a FastCGI script 
and then fasctcgi_pass the nginx to that?

Sorry for my questions...I think these are last ones ;)

Thank you so much!

More information about the nginx mailing list