'`php-cgi` executable consoles out php version and content type of php-cgi

When I run my php-cgi executable from OS command prompt, it also send back content type and PHP Version as an stdout inclusion. However, in php.exe this is not visible in Windows.

Command: php-cgi index.php

Code:

<?php
header('Content-Type: application/json');
header('Content-Type: text/html; charset=utf-8');
echo json_encode(array('$_SERVER' => $_SERVER));
?>
PHP-CGI Output:
X-Powered-By: PHP/8.1.3
Content-Type: text/html; charset=utf-8

{"$_SERVER":{"ALLUSERSPROFILE":"C:\\ProgramData","APPDATA"......}
PHP Output:
{"$_SERVER":{"ALLUSERSPROFILE":"C:\\ProgramData","APPDATA"......}

Is there a way I can avoid the powered by and default content type being shelled out when using php-cgi? Is there a setting? I did not find any in php.ini



Solution 1:[1]

php-cgi -q index.php

-q Quiet-mode. Suppress HTTP Header output.


To suppress "X-Powered-By: PHP/8.1.3"

php-cgi -d expose_php=off index.php

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1