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

Reply via email to