I am trying to call an external CGI script from PHP and return the output from that script. In essence my PHP website will do authorisation and setup some environment parameters and then call the CGI script using a proc_open(). I want to return the stdout stream from the script directly back to the browser as it already contains a suitable HTTP header.
However with everything I try, php adds its own header before the contents of the CGI programs output. Is there anyway of completely turning off the php automatic header generation ?
// Rough code to pass HTTP request through an external CGI script and return response
function processRepo1(){
$env = $_SERVER;
$env["GIT_PROJECT_ROOT"] = "/data/git";
$env["GIT_HTTP_EXPORT_ALL"] = "YES";
//$env["REQUEST_METHOD"] = "GET";
$env["PATH_INFO"] = "/DuneNvme.git/info/refs";
$env["QUERY_STRING"] = "service=git-upload-pack";
if(1){
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w")
);
}
else {
$descriptorspec = array(
0 => array("pipe", "r"),
1 => fopen("php://stdout","w"),
2 => fopen("php://stdout","w")
);
}
$process = proc_open("/usr/libexec/git-core/git-http-backend", $descriptorspec, $pipes, Null, $env);
if(is_resource($process)){
// Disable php headers somehow ...
fwrite($pipes[0], file_get_contents("php://input"));
fclose($pipes[0]);
echo stream_get_contents($pipes[2]);
fclose($pipes[2]);
echo stream_get_contents($pipes[1]);
fclose($pipes[1]);
$return_value = proc_close($process);
exit(0);
}
else {
return "Process execution error";
}
}