Sara Golemon wrote: >> Hello all, I hope this is the right place to write about this. I've been >> trying now for quite some time to integrate php into my non-apache server >> (completely c++ written by me). >> > Sounds like you want to use sapi/embed (or write a SAPI implementation of > your own which is notably more involved). Start with Wez's slides to get > a general idea, if you have questions later on, you can ask here or on > pecl-dev which is more non-core oriented than internals. > > -Sara > > > >http://www.php-kongress.de/2003/slides/internals_track/wez_embedding-php.pdf
Thank you for the quick response Sara! After looking in to this, I decided embedding it in might not be the best option after all. Instead, I decided to go with the php-cgi method, and am now facing I believe one last problem standing between me and full php in my webserver. I first removed the .sh script that's generated, and created my own little p_open that pipes stdin/stdout so I can read/write from the server. I export a good chunk of enviorment variables (listed below) after the fork in the child process before the execl of the php-cgi command, which seem to get most of the job done. I can GET php pages just fine (including more advanced things like phpBB), but POST is a whole different story, I can't get _ANY_ post data. Now, to do posts, I'm writing the post data onto stdin of the child process, which seems to be cgi/1.1 spec. I created my own very tiny c++ program to test it: #include <iostream> #include <fstream> int main() { std::string x; std::cin >> x; //read from stdin - comes from server std::cout << "Content-Type: text/html" << "\r\n\r\n" << "You entered: " << x << std::endl; //write to stdout - piped back to server return 0; } compiled it, and tested it by sending a post through that program, it echo'd the response to the web client containing all the POST data. To make sure it was correct, I put this small binary in apache's cgi dir, created a small post input form, posted to it, it echo'd exactly the same thing it did when run through my server through apache (eg: the raw unformatted post input). So, am I missing something? Do I need to set another enviorment variable to get the php-cgi module to read post data from stdin as per cgi/1.1? (as far as I can tell....) Enviorment variables set: putenv(SCRIPT_NAME=/testphp.php) putenv(REQUEST_METHOD=POST) putenv(CONTENT_LENGTH=0) putenv(CONTENT_TYPE=application/x-www-form-urlencoded) putenv(POST_DATA=p_email=asdf&p_test=woork) putenv(SCRIPT_NAME=/testphp.php) putenv(SERVER_NAME=localhost:5555) putenv(SERVER_PORT=5555) putenv(REMOTE_ADDR=127.0.0.1) putenv(DOCUMENT_ROOT=/home/user/ant/httpd/) putenv(SCRIPT_NAME=/testphp.php) putenv(PHP_SELF=/testphp.php) putenv(SCRIPT_FILENAME=/home/user/ant/httpd/testphp.php) putenv(DOCUMENT_NAME=testphp.php) putenv(SERVER_PROTOCOL=HTTP/1.1) putenv(SERVER_SOFTWARE=ANT-1.0) putenv(GATEWAY_INTERFACE=CGI/1.1) putenv(HTTP_USER_AGENT=User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.8) Gecko/20050524 Fedora/1.0.4-4 Firefox/1.0.4 ) putenv(HTTP_ACCEPT=text/xml,application/xml,application/xhtml+xml,text/html;q 0.9,text/plain;q=0.8,image/png,*/*;q=0.5) putenv(HTTP_ACCEPT_LANGUAGE=en-us,en;q 0.5) putenv(HTTP_ACCEPT_CHARSET=ISO-8859-1,utf-8;q 0.7,*;q=0.7) putenv(REDIRECT_STATUS=200) putenv(HTTP_ACCEPT_ENCODING=gzip,deflate) Method(s) tried for sending post data to php-cgi: (At the same time, and seperately) 1) write(childstdin, poststring.c_str(), poststring.size()); 2) command.append("php-cgi < echo \"); command.append(poststring); command.append("\""); pipe_command(command); // export variables, run custom popen, before execl(bin/sh -c command null) redir stdin and stdout, create third notify pipe, notify parent when enviorment variables are registered in child, child waits until any 1 charactor is written to notify pipe, parent write's to child's stdin, notify's child when write is finish, child runs execl on command, parent waits for child to finish, after child exits() parent reads stdout of child and let's the webserver take it on it's merry little way to the client adding all the server specific header fields and all that. It works with my own custom "cgi" module above, but not php-cgi, for posts only. It works on get's with both. Thanks in advance, this is driving me nuts! :) Oh, btw, I have both: php-cgi --version PHP 5.0.4 (cgi-fcgi) (built: May 9 2005 11:20:57) Copyright (c) 1997-2004 The PHP Group Zend Engine v2.0.4-dev, Copyright (c) 1998-2004 Zend Technologies // came with fedora php-cgi2 --version PHP 5.1.2 (cgi) (built: Jan 31 2006 00:42:07) Copyright (c) 1997-2006 The PHP Group Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies // I just installed and tried to see if it would make a difference. to work with, and can get and install any other version if needed. Thanks again! -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php