Fix "headers are already sent" introduced with #6519

This should fix the the `headers are already sent` problem which have been introduced with #6519. I'm somewhat confused as the PHP log isn't reporting this problem, anyways, this should fix the unit tests.

Needs a backport to stable6.

\cc @DeepDiver1975