Report back: Ok I have php working as cgi from my server (written in c). I could find so little documentation on this that my solution is inevitably a hack. Here's how my server handles php requests, using test.php?argone=11111&argtwo=22222 as an example -
Set an environment variable "phpvars" with the name of the script you want to call, plus the arguments passed from the browser. For example the example string would create phpvars="php=test.php&argone=11111&argtwo=22222"
Create two pipes, hooking your server's stdout to the stdin end of the php binary you're going to spawn and your stdin to the stdout of the other's stdin. (see http://msdn2.microsoft.com/en-us/library/ms682499(VS.85).aspx for a surprisingly decent howto)
Call the php binary (CreateProcess) giving it the name of a preprocessor script (see below). This script creates superglobals from "phpvars" and then runs the script (test.php) you ultimately wanted to run.
All echos are fed back to the server's stdin, etc etc.
Like I said, a hack. I haven't bothered to set $_GET's from the environment var and I dont pass any $_POST's through stdin because right now I dont need em, but that would be trivial to add.
Here's a basic preprocessor script with no error checking....
<?php
// Set up the superglobals
$fileToLoad = '';
$envs = getenv('phpvars');
$env = explode("&", $envs);
for ($c = 0; $c < sizeof($env); $c++)
{
$envVar = explode("=", $env[$c]);
$_REQUEST[$envVar[0]] = $envVar[1];
if ($envVar[0] == 'php')
$fileToLoad = $envVar[1];
}
if ($fileToLoad != '')
include($fileToLoad);
?>