Search code examples
phpfastcgi

PHP: How to respond with a custom protocol other than HTTP?


My application is served by php-fpm so PHP will detect that and try to format the response to make it a valid HTTP response. I want to change that:

<?php
ini_set('html_errors', 0);
$x = "<body></body>";
header_remove('Content-type');
echo $x;

The current output (Not what I want):

CRLF (empty line)
<body></body>

I want to have a full control over php response and remove empty line at the beginning:

<body></body>

How can I do it? How can I have a full control over the output in FastCGI environment.


Solution

  • You cannot remove the newline between the header and the response body.

    They are hardcoded in the FPM engine:

    If you don't want the newline, put something in front of the FPM that modifies the response before returning it to the requesting client.