如何将PHP和MySQL合并到我自己制作的C ++ webserver中 [英] How to incorporate PHP and MySQL into my home made C++ webserver

查看:61
本文介绍了如何将PHP和MySQL合并到我自己制作的C ++ webserver中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

制作了一个我在工作中使用的C ++网络服务器。没什么,只是一个套接字监听和服务......但我想扩展它来运行PHP和MySQL。任何指针都会受到赞赏。

Made a C++ webserver that I using for at work. Nothing much, just a socket listening and serving... But I want to extend it to run PHP and MySQL. Any pointers will be appreciated.

推荐答案

这是一个很高的命令但是这里有一个关于如果我有类似任务我会怎么想的概述。 />


关于与Web服务器相关的所有事情,通常认为像Apache一样好。现在我不打算去阅读Apache Web Server的所有源代码并告诉你它是如何工作的(如果你有时间和坚韧,你可以这样做)所以我要告诉你我认为它可以工作。



Web服务器基本上有2个任务,大多数人都会错误地解决问题。首先将网页发送到临时连接的客户端,然后将传入的请求路由到生成网页的内容。



如果您这样想,那么Web服务器是相当的简单而且不应该变成臃肿和不稳定的怪物。

我想你已经满足了要求1并且可以发送页面。现在你需要满足要求2,即将除了简单静态页面以外的其他东西的请求路由到Web服务器本身以外的其他东西来生成页面。



My理解是,最好通过按如下方式分解请求来完成。



请求到达哪个端口?例如,各种垃圾进入的通用端口或分配给FTP的专用端口。如果可以根据端口做出路由决定,则可以将请求发送到FTP处理程序,例如,Web服务器的工作完成,直到准备好发送响应为止。



请求到达的协议是什么?可能是FTP,HTTP或像PHP一样包含在HTTP中的东西。再次路由,如果它可以被识别为具有可用处理程序的东西。



在主Web服务器级别上,它几乎就是这样。如果没有识别出特定的协议,那么它就会在错误日志的方向上被丢弃,并且格式良好的404消息排成一行发送给客户端。



因此,您需要PHP的某种插件或处理程序,它只接收PHP请求的PHP部分。那是'那里的纯PHP,我不是PHP所以我会把它留给你。



MySQL更有趣,因为它据我所知,它没有自己的HTTP打包协议。所以像其他人一样,你需要做一个或借用别人的。通常借用别人的东西比起来更容易,我想有很多MySQL特定的文章和例子可以使用。在MySQL的情况下,有趣的部分将接收请求并将它们转回Web页面和网页的一部分,其余部分主要是管道。
That''s a tall order but here''s an outline of how I would think if I had a similar task.

In regards to all things Web Server related it is generally considered a good thing to make like an Apache. Now I''m not going to go and read all the source code for Apache Web Server and tell you how it works ( you can do that if you''ve got the time and tenacity ) so I''m going to tell you how I think it could work.

A Web Server has essentially 2 tasks which most people get the wrong way round. Firstly sending out Web Pages to temporarily connected clients and Secondly routing incoming requests to something that generates Web Pages.

If you think of it like that then a Web Server is quite simple and shouldn''t grow into a bloated and unstable monstrocity.
I guess you''ve already met requirement 1 and can send out pages. Now you need to meet requirement 2 which is to route requests for something other than a simple static page to something other than the Web Server itself to generate the page.

My understanding is that this is best done by breaking down the request as follows.

Which port did the request arrive on? A general port on which all sorts of junk comes in or a specialist port assigned to FTP for example. If a routing decision can be made on the basis of the port then the request can be sent off to the FTP handler for example and the Web Server''s job is done until a reponse is ready to be sent.

Which protocol did the request arrive as? Could be FTP, HTTP or something wrapped inside HTTP like PHP. Again route if it can be identified as something with an available handler.

At the main Web Server level that''s pretty much it. If no specific protocol is identified then it''s junked in the direction of the error log and a nicely formatted 404 message is lined up to be sent to the client.

So you need a plugin or handler of some kind for PHP that only recieves the PHP parts of PHP requests. That''s pure PHP from there on and I don''t PHP so I''ll leave that to you.

MySQL is a little more interesting because it doesn''t have it''s own HTTP packaged protocol as far as I know. So like everyone else you''re going to need to make one up or borrow someone else''s. Usually borrowing someone else''s is easier at least to start with and I guess there are lots of MySQL specific articles and examples about to work from. The fun part in the case of MySQL will be taking the requests and turning them back into Web Pages and parts of web Pages, the rest is mostly plumbing.


对此进行了一些研究。 web并发现有三种方法可以实现PHP部分

1.使用php-cgi.exe作为CGI进行通信(同时设置一些全局变量)

2.使用fastcgi(类似于第1和更快,只是我不知道这是什么)

3.在你的网络服务器代码中构建一个PHP模块(最难实现但是表演者最快)



我现在的问题是,如何从php-cgi.exe获取输出
Did a little more research on the web and found out that there are 3 ways the PHP part can be achieved
1. Communicating with php-cgi.exe as a CGI (while setting some global variables)
2. Using fastcgi (similar to No. 1 and faster, only that I don''t have a clue what this is)
3. Building a PHP module into your webserver code (hardest to implement but fastest in terms of performers)

My question now is, how do I get the output from php-cgi.exe


这篇关于如何将PHP和MySQL合并到我自己制作的C ++ webserver中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆