开发者

C++ Serve PHP documents?

开发者 https://www.devze.com 2022-12-19 05:54 出处:网络
I am writing a small web server, nothing fancy, I basically just want to be able to show some files. I would like to use PHP though, and im wondering if just putting the php code inside of the html wi

I am writing a small web server, nothing fancy, I basically just want to be able to show some files. I would like to use PHP though, and im wondering if just putting the php code inside of the html will be fine, or if I need to actually use some type of PHP library?

http://www.adp-gmbh.ch/win/misc/webserver.html

I just downloaded that and I am going to use that to work off of. Basically I am writing a ser开发者_如何转开发verside game plugin that will allow game server owners to access a web control panel for their server. Some features would be possible with PHP so this is my goal. Any help would be appreciated, thanks!


The PHP won't serve itself. What happens in a web server like Apache is before the PHP is served to the user it is passed through a PHP parser. That PHP parser reads, understands and executes anything between (or even ) tags depending on configuration. The resultant output, usually still HTML, is served by the web server.

There are a number of ways to achieve this. Modules to process PHP have been written by Apache but you do not have to use these. PHP.exe on windows, installed from windows.php.net, will do this for you. Given a PHP file as an argument it will parse the PHP and spit the result back out on the standard output.

So, one option for you is to start PHP.exe from within your web server with a re-directed standard output to your program, and serve the result.

How to create a child process with re-directed IO: http://msdn.microsoft.com/en-us/library/ms682499%28VS.85%29.aspx however, you won't be writing the child process, that'll be PHP.exe

Caveat: I am not sure from a security / in production use perspective if this is the most secure approach, but it would work.


PHP needs to be processed by the PHP runtime. I'm assuming the case you're talking about is that you have a C++ server answering HTTP queries, and you want to write PHP code out with the HTML when you respond to clients.

I'm not aware of any general-purpose PHP library. The most straightforward solution is probably to use PHP as a CGI program.

Here's a link that might be useful for that: http://osdir.com/ml/php-general/2009-06/msg00473.html

This method is nice because you don't need to write the HTML+PHP out to a file first; you can stream it to PHP.


You need execute the PHP page to serve the page it generates.

The easiest thing for you to do would be to add CGI support to your webserver in some basic form. This is non-trivial, but not too difficult. Basically you need to pass PHP an environment and input, and retrieve the output.

Once you have CGI support you can just use any executable, including PHP, to generate webpages.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号