There is some advice on the FAQ on how to handle this situation. Quoting the docs.
How do I read data from a stream as it arrives?
There are 3 problems you have to deal with:
- The Apache parsers read the entire data stream into a buffer before
they start parsing; you need to change this behaviour, so that they
analyse "on the fly"
- The Apache parsers terminate when they reach end-of-file; with a data
stream, unless the sender drops the socket, you have no end-of-file,
so you need to terminate in some other way
- The Apache parsers close the input stream on termination, and this
closes the socket; you normally don't want this, because you'll want
to send an ack to the data stream source, and you may want to have
further exchanges on the socket anyway.