PHP 如何与 Apache 交互? [英] How does PHP interface with Apache?

查看:26
本文介绍了PHP 如何与 Apache 交互?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我几乎已经在 J​​ava 下编写了一个 HTTP/1.0 兼容的 Web 服务器(没有商业用途,这只是为了好玩)并且基本上我想包括 PHP 支持.我意识到这根本不是一件容易的事,但我认为这将是一项不错的成就.​​

I've almost finished writing a HTTP/1.0 compliant web server under Java (no commercial usage as such, this is just for fun) and basically I want to include PHP support. I realize that this is no easy task at all, but I think it'll be a nice accomplishment.

所以我想知道 PHP 如何准确地与 Apache Web 服务器(或任何其他 Web 服务器)交互,以便我可以从中学习并编写我自己的 PHP 包装器.它不一定是 mod_php,我不介意编写 FastCGI 包装器 - 据我所知,它也能够运行 PHP.

So I want to know how PHP exactly interfaces with the Apache web server (or any other web server really), so I can learn from it and write my own PHP wrapper. It doesn't necessarily have to be mod_php, I don't mind writing a FastCGI wrapper - which to my knowledge is capable of running PHP as well.

我认为 PHP 需要的只是发送到客户端的输出(因此它可以解释 PHP 部分)、来自客户端的完整 HTTP 请求(因此它可以提取 POST 变量等)以及客户端的主机姓名.然后您只需将解析后的 PHP 代码写入输出流.可能会有更多的东西,但本质上这就是我认为它起作用的方式.

I would've thought that all that PHP needs is the output that goes to client (so it can interpret the PHP parts), the full HTTP request from client (so it can extract POST variables and such) and the client's host name. And then you simply take the parsed PHP code and write that to the output stream. There will probably be more things, but in essence that's how I would have thought it works.

从我目前收集到的信息来看,apache2handler 提供了一个 API,PHP 使用它来连接"到 Apache.我想查看 apache2handler 和 php5apache2.dll 左右的源代码是一个想法,但在我这样做之前,我想我会先问一下.

From what I've gathered so far, apache2handler provides an API which PHP makes use of to 'connect' to Apache. I guess it's an idea to look at the source code for apache2handler and php5apache2.dll or so, but before I do that I thought I'd ask SO first.

如果有人有更多信息、经验或与此相关的某种规范,请告诉我.

If anyone has more information, experience, or some sort of specification that is relevant to this then please let me know.

提前致谢!

推荐答案

有 3 种方式可以从 Apache 调用 PHP:

There are 3 ways PHP can be invoked from Apache:

1) 作为一个模块 - 这涉及将 php 解释器与网络服务器发布的钩子库相链接

1) as a module - this involves linking the php interpreter against a library of hooks published by the webserver

2) CGI - 网络服务器为每个请求启动一个解释器实例,并通过标准输入、命令行和环境变量将参数传递给解释器,标准输出被发送到客户端,标准错误应该被写入错误日志

2) CGI - the webserver starts up an instance of the interpreter for each request and passes parameters to the interpreter via stdin, the command line and environment variables, stdout is sent to the client and stderr should be written to the error_log

3) fastCGI - 这消除了为每个请求启动一个新进程的开销 - 解释器作为守护进程运行

3) fastCGI - this eliminates the overhead of starting a new process for each request - the interpreter runs as a daemon

CGI 是最简单的实现,但不能很好地扩展/执行,该模块将是迄今为止最难的.FastCGI 几乎与模块方法一样快.CGI 和 fastCGI 是开放的、有据可查的 API.

CGI is the simplest to implement but does not scale/perform well, the module would be the hardest by far. FastCGI is nearly as fast as the module approach. CGI and fastCGI are open, well documented APIs.

还有其他方法可以实现您的目标 - 例如

There are other ways of achieving your goal - e.g. Quercus

C.

这篇关于PHP 如何与 Apache 交互?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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