Hi,

to answer this question you need to have some experience
about php...

i'm planning to create a http server that supports cgi. Does anyone 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 is no output, even not the headers).

I'll bet that someone of you already have created a server.

---------------------------------
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-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!

> <conoi.h>
> getch() to look at the program output
Already Extinct.Try using newer standard coding styles.

>Hi,
>to answer this question you need to have some experience
>about php...
Even though relevant sounds a bit rude.It sounds like "Read my thread if you are educated enough".

yes yes. Could somebody just give
a proper answer?
Php.net hould have its own guides
for this. :-/

This article has been dead for over six months. Start a new discussion instead.