I have a cgi script that will output a “generating your output…” message followed a few seconds later with “done…”. However, no matter what I do, no output reaches the browser until the script finishes completely. Here is a small example script:
#!/usr/bin/env python3
# -*- coding: utf8 -*-
import sys
import time
print("""Content-Type: text/html
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Testing ...</title>
</head><body>""")
print("<p>Nothing to see here yet</p>")
sys.stdout.flush()
time.sleep(5)
print("<p>Done</p>")
print("</body></html>")
You can try this at home with curl https://elnadisc.com/cgi-bin/test.cgi
if you feel so inclined. If you do, what you’ll see is that nothing happens for five seconds, and then all of the output shows up at once. Obviously, Apache is buffering the data. Headers indicate that HTTP/2 protocol is in use.
Is there a way to force Apache to send what the script has generated so far? Preferably in the .htaccess file or through some property emitted by the script.
2