I'm working on something similar, here's the pseudo-code of what
happens to ensure the PHP script run by my server doesnt see any
difference than when it runs under apache or others...

Say the php file to execute is "index.php" and it was called from a
form post, the form tag also specified GET arguments like this <FORM
METHOD=POST ACTION="index.php?somegetvar=getvalue">...

The PHP script will expect this:
$_GET['somegetvar'] = "getvalue";
$_POST['somepostvar'] = "postvalue";
and
$_REQUEST['somegetvar'] = "getvalue";
$_REQUEST['somepostvar'] = "postvalue";

To get this working, the server first has to parse the HTTP message to
grab the GET arguments in the URI.  After this, the server has to
parse the Body entity of the HTTP message for POST values.  Once the
server has all the information, it can execute the php script.

I personally like to use popen("php", "w") which opens a write-only
pipe to the php process... it's like just typing "php" on the
commandline, php then listens on stdin for the code and it executes
when it receives EOF (on the commandline this happens after a ctrl-d
on linux), using popen() this happens on a pclose().

Once you've popen()ed php, you start writting something like this:
<?PHP
$_GET['somegetvar'] = "getvalue";
$_POST['somepostvar'] = "postvalue";
$_REQUEST['somegetvar'] = "getvalue";
$_REQUEST['somepostvar'] = "postvalue";
//[...] Also handle other superglobals here

require("index.php");

?>

And bingo!

Hope this helps, good luck!


On Mon, Jun 8, 2009 at 9:29 AM, Jasper<jazu...@luukku.com> wrote:
> Hi,
> i'm planning to create a win32 http server that supports cgi. Does anybody 
> see the problem in C++ -source? Php doesn't give any output, but if I don't 
> set the rfc3875 environment variables, all output comes
> normally (expect post and other variables aren't set).
> Only what I'm able to set is $_GET -variables as
> script arguments.
>
> So how can I set post variables and others, like RAW_POST_DATA?
> The c code above lets php to read the script by itself and post -variables 
> are written to stdin pipe. Output
> should be able to be readed from stdout (problem is
> that there are no output, even not the headers).
>
> I hope that you understand what I mean...
>
> ---------------------------------
> Test script: (D:\test.php)
> ---------------------------------
> <?php echo 'Wd: ',getcwd(),' var=',$_POST['var']; ?>
>
> ---------------------------------
> C++ source:
> ---------------------------------
> #include <windows.h>
> #include <conio.h>
> #include <stdio.h>
>
> int main()
> {
>    SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES)};
>    sa.bInheritHandle = 1;
>    sa.lpSecurityDescriptor = NULL;
>
>    HANDLE hStdoutR, hStdoutW, hStdinR, hStdinW;
>    CreatePipe(&hStdoutR,&hStdoutW,&sa,0);
>    SetHandleInformation(hStdoutR,HANDLE_FLAG_INHERIT,0);
>    CreatePipe(&hStdinR,&hStdinW,&sa,0);
>    SetHandleInformation(hStdinW,HANDLE_FLAG_INHERIT,0);
>
>    STARTUPINFO si = {sizeof(STARTUPINFO)};
>    PROCESS_INFORMATION pi;
>    si.dwFlags = STARTF_USESTDHANDLES;
>    si.hStdOutput = hStdoutW;
>    si.hStdInput = hStdinR;
>
>    char env[255] = 
> "REQUEST_METHOD=POST\0CONTENT_LENGTH=17\0CONTENT_TYPE=application/x-www-form-urlencoded\0SCRIPT_FILENAME=D:\\test.php";
>    if(!CreateProcess(NULL,"php-5.2.9-1-Win32\\php-cgi.exe 
> D:\\test.php",NULL,NULL,1,NORMAL_PRIORITY_CLASS,env,NULL,&si,&pi))
>        return 0;
>    CloseHandle(hStdoutW);
>    CloseHandle(hStdinR);
>
>    DWORD dwWritten = 0;
> //Write post data here?
> if(!WriteFile(hStdinW,"var=post+variable",20,&dwWritten,NULL))
>        return 0;
>
>    CloseHandle(hStdinW);
>
>    char buf[1000] = {0};
>    DWORD dwRead = 0;
>    while(ReadFile(hStdoutR,buf,sizeof(buf),&dwRead,NULL) && dwRead != 0){
>        printf(buf);
>    }
>    printf("|\n\nEND");
>    CloseHandle(hStdoutR);
>
>    getch();
>
>    return 0;
> }
> ------------------------------
> Thanks!
> Jasper
>
> ...................................................................
> Luukku Plus paketilla pääset eroon tila- ja turvallisuusongelmista.
> Hanki Luukku Plus ja helpotat elämääsi. http://www.mtv3.fi/luukku
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to