I want to make a CGI that launches a program and displays the output in the web-browser in real-time. Real-time here means as soon as a line of output is produced by the program it should be displayed on the browser page.
I choose to write it in bash to wrap the program execution so I can process request parameters.
webbrowser -> nginx+fastcgi -> bash -> program
I have a testing program that outputs one line every half a second, 10 times.
I thought I could declare a plain text context type in response header and then exec the program.
Unfortunately the output appears in the browser only at the end of the execution all at once. I tested it in Firefox and curl.
I have tested many options and any combination of them to workaround the issue :
- disable buffering in nginx with
fastcgi_buffering off
directive - add
X-Accel-Buffering
header - use
stdbuf -oL program
- use xml http request (XHR) + server side event (SSE) instead of plain text.
Nothings works.
I guess the buffering issue is between nginx and bash but I find no way to disable it.
What can I try ?