如何开始通过 Apache 编写应用程序服务器?
对于我的大学项目,我想用 C 创建一个在 Apache 上运行的简单应用程序服务器。像 .php、.asp、.jsp 一样,我的文件的扩展名是 .sas。
我已经编写了一个解析器,它读取 .sas 文件并生成输出。例如,考虑一个包含以下代码的文件 index.sas:
<%
echo "Hello";
%>
现在,如果我执行:
sas索引.sas
结果将是:
你好
现在我想使用这个程序作为 Apache 上的应用程序服务器就像 PHP、Tomcat 等通过 Apache 运行。我 听说过 cgi-bin 但我认为 PHP 使用不同的方法。我想要 了解 PHP 使用的方法。
请指教。
For my college project, I want to create a simple application server in C that runs over Apache. Like .php, .asp, .jsp, the extension of my files would be .sas.
I have already written a parser which reads the .sas files and generates the output. For example, consider a file index.sas with the below code:
<%
echo "Hello";
%>
Now, if I execute:
sas index.sas
The result would be:
Hello
Now I want to use this program as an
application server over Apache just as
PHP, Tomcat, etc. work over Apache. I
have heard of cgi-bin but I think PHP
uses a different approach. I want to
learn the approach which PHP uses.
Please advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
稍作修正:不需要 Apache HTTP Server 即可将 Apache Tomcat 作为 Web 服务器运行。 Apache Tomcat 本身已经是一个成熟的网络服务器。您的困惑可能是由 Tomcat Connector 引起的,它可用于连接 Apache HTTP Server 和Apache Tomcat 一起能够在同一个 HTTP 端口后面为 PHP/JSP 提供服务。
至于您的实际问题,PHP 可以作为 CGI 模块或 ASAPI(Apache Server API)模块安装。如果您想为 Apache HTTP Server 编写 CGI 模块,那么您可能会找到 这个文档很有用。如果您想编写 ASAPI 模块,那么您可能会发现这些文档很有用。
Little correction: Apache HTTP Server is not required to be able to run Apache Tomcat as webserver. Apache Tomcat is at its own already a full fledged webserver. Your confusion is probably caused by the Tomcat Connector which could be used to connect Apache HTTP Server and Apache Tomcat together to be able to serve PHP/JSP behind one same HTTP port.
As to your actual question, PHP can be installed as CGI module or ASAPI (Apache Server API) module. If you want to program a CGI module for Apache HTTP Server, then you may find this document useful. If you want to write an ASAPI module, then you may find those documentations useful.
您需要使用 Apache API 编写一个模块。
一些带有示例的基本文档可以在这里找到。
http://www.auburn.edu/docs/apache/mod/mod_example。 html
You need to write a module utilizing the Apache API.
Some basic documentation with examples can be found here.
http://www.auburn.edu/docs/apache/mod/mod_example.html
不不不!!!我说“不”够了吗? :)
您不需要创建新模块或查看 PHP 源代码。谈论使用方形巨石重新发明轮子。
最简单的方法是使用 mod_cgi。也就是说,您使用 CGI 让 Apache 将请求转发到您的 SAS 解释器。
[Apache 1.3x] - http://httpd.apache.org/docs/ 1.3/mod/mod_cgi.html
[Apache 2.0x] - http ://httpd.apache.org/docs/2.0/mod/mod_cgi.html
[CGI] - http://en.wikipedia.org/wiki/Common_Gateway_Interface
现在,如果您不想使用 CGI(不知道为什么,除非您的作业指示明确禁止),那么是的,您将必须创建一个模块。为此,请将此作为起点(由谷歌提供):
http:// /twobit.net/tutorials/apache2_modules/tut1/tutorial1.html
不过祝你好运。它可能会变得劳动密集型。
希望有帮助。
No, no, no!!! Did I say "no" enough? :)
You don't need to create a new module or look at PHP source code. Talking about re-inventing the wheel using a square boulder.
The easiest thing to do is to use mod_cgi. That is, you use CGI to have Apache forward the request to your SAS interpreter.
[Apache 1.3x] - http://httpd.apache.org/docs/1.3/mod/mod_cgi.html
[Apache 2.0x] - http://httpd.apache.org/docs/2.0/mod/mod_cgi.html
[CGI] - http://en.wikipedia.org/wiki/Common_Gateway_Interface
Now, if you do not want to use CGI (don't know why unless it is expressively forbidden by your homework instructions), then yeah, you will have to create a module. For that take a look at this as an starting point (courtesy of google):
http://threebit.net/tutorials/apache2_modules/tut1/tutorial1.html
Good luck with that, though. It could become labor-intensive.
Hope it helps.