I tried using the "streaming body" feature of the PSGI spec, by calling $writer->close and then doing the cleanup work, but that seems to be blocking also; plus, is a bit of a complicated way of doing it when the rest of the app doesn't really need streaming.PerlCleanupHandler
There is no cleanup Apache phase, it exists only inside mod_perl. It is used to execute some code immediately after the request has been served (the client went away) and before the request object is destroyed.
There are several usages for this use phase. The obvious one is to run a cleanup code, for example removing temporarily created files. The less obvious is to use this phase instead of
PerlLogHandlerif the logging operation is time consuming. This approach allows to free the client as soon as the response is sent.