If you want to start PHP scripts in an own http server, the best way would be to create a SAPI for it. SAPIs only have to implement callbacks for the PHP engine to write stuff to the output stream, read input stream in POST requests and populate variables and output headers. The embed SAPI is a striiped down SAPI to make it simplier to embed PHP in applications outside webservers, so EMBED implements all these features in a minimalistic way to get scripts running.
My opinion: Use another SAPI module as entry point and write your own SAPI code. I am the maintainer of NSAPI SAPI, I could help you, if needed. Uwe ----- Uwe Schindler [EMAIL PROTECTED] - http://www.php.net NSAPI SAPI developer Bremen, Germany > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Sent: Monday, April 28, 2008 3:50 PM > To: internals@lists.php.net > Subject: [PHP-DEV] passing Cookies and other environment stuff to PHP SAPI > Embed > > Hi > > I'm trying to write the php processing part of a small httpd. I want to > use > the SAPI Embed for interpreting php scripts. But I can't find a way to > specify the content of variables like $_COOKIE, $_REQUEST, $_SERVER etc. > > Is there any function to initalize the SAPI header with all this stuff? > > That's what my little programm looks like at the moment: > > <cpp> > #include <php_embed.h> > #include <iostream> > #include <string> > > using namespace std; > > string output = ""; > > int store_string (const char *str, unsigned int str_length TSRMLS_DC) > { > if(strlen > 0) > output += str; > > return SUCCESS; > } > > int main(int argc, char* argv[]) > { > // pass output of script to store_string() instead of printing it to > stdout > php_embed_module.ub_write = store_string; > > PHP_EMBED_START_BLOCK(argc, argv) > > // php_request_startup(TSRMLS_C); > sapi_header_struct *h; > zend_llist_position pos; > > zval retval; // return value > // execute script > zend_eval_string("include 'test.php';", &retval, "script" TSRMLS_CC); > cout << "\nscript output:\n" << output << endl; > > > // convert retval to long > convert_to_long(&retval); > cout << "\nretval: " << Z_LVAL(retval) << endl; > // free memory > zval_dtor(&retval); > > > cout << "\nreading header:" << endl; > // get header (SG = SAPI Globals) > sapi_headers_struct *sapi_headers = &(SG(sapi_headers)); > // read first element (= header line) > h = (sapi_header_struct*)zend_llist_get_first_ex(&sapi_headers- > >headers, &pos); > // while existing elements > while (h) > { > // print them > cout << h->header << endl; > // get next element > h = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers- > >headers, &pos); > } > > PHP_EMBED_END_BLOCK() > > return 0; > } > </cpp> > > Before calling zend_eval_string() to interpret the script there has to be > some way to pass all the client information like Cookies and stuff to the > SAPI, but I can't find a way to do this. Unfortunately there is no > documentation at all for this API. > > Is there anyone who could give me some hints, or a small code snippet? > > > Regards, > Alex > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php