I am looking for an efficient way of responding to an http request. When a http request is received (apache/php webserver environment), I want to know if I can obtain a reference to php's response instance inside a c++ library method and write the output data directly to the response instance within C++ context.
Asked
Active
Viewed 177 times
1
-
1How about writing an apache plugin and bypassing php altogether? – Alex Wilson Jul 07 '12 at 19:43
-
You are probably looking at [writing a php extension](http://www.php.net/manual/en/internals2.php) if you want to tap into PHP's response and output data. The question may now by, why do you need to do this, and is there any other way to do what you want? – drew010 Jul 07 '12 at 19:48
1 Answers
1
Normally, you'd simply redirect the request to your external C/C++ program through mod_fastcgi, processs it completely in your program and write the repsponse to the client.
If not possible, you could include the program output into the generated web page by accessing your program from Apache as a server side include (SSI).
From PHP, you can also perform a system call to the external program and process the returned output as shown in the link.
Some simple C examples are provided in the fastcgi documentation.
To write a PHP extension in C/C++ (here and there) and make that work in Apache (through mod_php) is possible, but is considered rocket science and therefore discouraged ;-)

rubber boots
- 14,924
- 5
- 33
- 44
-
+1 for the hint about writing extension in c++. it's a wonderful thing for sites that are frequented a lot – cppanda Jul 07 '12 at 23:40
-
Thank you. I went for fastcgi approach and I likeit. It is probably the best approach when native language library needs to write html output with Apache's http context. The method of using PHP extensions seems to be a bit over complicated. – jsa Nov 24 '12 at 17:09