I’m writing an Nginx module and I’d like to better understand how Nginx
content handlers work and how the Nginx main loop works.
As far as I know, Nginx content handler functions are supposed to create
a chain link of buffers containing the response data, and then call
ngx_http_output_filter(r, &the_chain_link) which will then take care of
passing this data to the next output filter and eventually sending the
data to the HTTP client.
How does one deal with situations in which the content handler function
cannot immediately generate a response? For example, suppose my content
handler must first fetch some data from MySQL. Since Nginx is an evented
server, I imagine that I need to do something like this:
- Connect to MySQL and send a request to it.
- Register the MySQL client file descriptor on the Nginx main loop.
- The Nginx main loop notifies me when the MySQL fd becomes readable.
- I read the MySQL response, generate HTTP response data, and call
But how do I do step 2? Which function do I need to call? What should I
return in my content handler function after having executed step 2?