I'm developing a little web server in C++, now I'm trying to implement PHP support for my WS, or better I'm trying to figure out how to implement that. But I've got some doubts: for now I have the client's request in a std::string, if it's a static request there's no problem: let's find file and put in on socket buffer; if it's a dynamic request(PHP only for now), of course I will need to call the interpreter(std::system() ??). Now my mainly doubt is about forms, I get my POST request and I save form fields in a string, but now: How can I fill $_POST used in my php script and call the interpreter? I could put my fields string as argv by "php -f file.php "fields string" but ,of course, it's awful.
Asked
Active
Viewed 693 times
0
-
1You just need the `php-cgi` binary, set up some (a lot) environment variables, and push the POST request body as stdin to the interpreter. – mario Dec 09 '11 at 00:27
-
1possible duplicate of [How does a webserver interface with PHP](http://stackoverflow.com/questions/7056697/how-does-a-webserver-interface-with-php) – mario Dec 09 '11 at 00:27
-
Thank you very much, but how can i put POST request body as php://stdin? – alkz Dec 10 '11 at 00:40
1 Answers
1
To pass the POST body, you basically pipe it in
echo "$POST_BODY" | php-cgi
For C and C++ you don't want to use just popen()
, but also capture the output and stderr. So you need something like: how to control popen stdin, stdout, stderr redirection?