在 IIS 7.0 上的 CGI 可执行 EXE 中使用 NPH 模式 - 这可以是“实时的吗?”

发布于 2024-11-25 04:49:54 字数 2912 浏览 2 评论 0原文

我正在编写一个在 IIS 7.0 服务器上运行的原型 CGI 应用程序,这最终会导致该应用程序发送许多 http 分块响应,这些响应是为响应查询而生成的,可能需要一些时间才能生成实际数据。

在深入研究这方面(即生成真实数据)之前,我想测试我的 cgi 应用程序实际上是否在非解析标头模式下运行(即 cgi 应用程序本身生成所有标头,并且 IIS 只是将所有输出返回到请求 http 浏览器/代理,

所以我编写了一个简单的应用程序,它返回以下内容(注意时间戳 - 每个带时间戳的行之间有 1 秒的暂停,正如文本所暗示的,这只需 10 秒多一点即可执行 - 事实上,您可以运行 当我在服务器上安装

HTTP/1.1 200 OK
Date: Sun, 17 Jul 2011 09:07:47 GMT
Content-Type: text/plain
Transfer-Encoding: chunked

17;
NPH CGI Chunked Example

4D;
the fat cat sat on the mat, perplexed at the antics of the quick brown fox.

2D;
counting ... 1...  the time is now 09:07:48

2D;
counting ... 2...  the time is now 09:07:49

2D;
counting ... 3...  the time is now 09:07:50

2D;
counting ... 4...  the time is now 09:07:50

2D;
counting ... 5...  the time is now 09:07:51

2D;
counting ... 6...  the time is now 09:07:52

2D;
counting ... 7...  the time is now 09:07:53

2D;
counting ... 8...  the time is now 09:07:54

2D;
counting ... 9...  the time is now 09:07:55

2E;
counting ... 10...  the time is now 09:07:56

18;
NPH Chunked Example Ends

0

exe 并在 Internet Explorer 中打开它时,会显示预期的文本(时间有所不同,因为我在一天中的不同时间和不同时区运行它们)。 ):

NPH CGI Chunked Example
the fat cat sat on the mat, perplexed at the antics of the quick brown fox.
counting ... 1...  the time is now 16:14:58
counting ... 2...  the time is now 16:14:59
counting ... 3...  the time is now 16:15:00
counting ... 4...  the time is now 16:15:01
counting ... 5...  the time is now 16:15:02
counting ... 6...  the time is now 16:15:03
counting ... 7...  the time is now 16:15:04
counting ... 8...  the time is now 16:15:05
counting ... 9...  the time is now 16:15:06
counting ... 10...  the time is now 16:15:07
NPH Chunked Example Ends

但是 - 在整个 10 秒过去之前不会显示任何内容。 (注意 - Chrome 中的结果相同)

为了确保,我在文本编辑器中制作了一个 http 请求,并将其粘贴到端口 80 上的 telnet 到服务器,并观察到整个响应之前有 10 秒的间隙,如上所示。

无论 exe 是否有前缀“nph-”,我都会得到相同的结果 - 我在 telnet 中使用“nph-hello.exe”、“nphhello.exe”和“hello.exe”执行了相同的测试,使用以下内容:(

注意:识别地址已针对本文进行调整)

GET /cgi-bin/nph-hello.exe HTTP/1.0
Host: www.myserver.com:80
From: [email protected]
User-Agent: telnet/1.0

(有关 exe 命名前缀的相关性,请阅读 http://support.microsoft.com/default.aspx?scid=kb ;EN-US;q176113 在“解决方案”下以“作为解决方法...”开头)

我似乎没有观察到与 exe 名称前缀相关的 telnet 中任何明显的输出差异,这使我相信此信息要么已经过时,要么需要启用其他功能才能打开此功能,这显然需要在 cgi 应用程序启动之前发生 - 这解释了为什么使用前缀而不是应用程序本身所做的事情 - 即 IIS需要知道是否等待响应),

而从表面上看,它正在实现所需的结果 - 数据找到发送请求的 http 代理的方式 - 我希望它实时发生,因此进度更新可以显示为已提出请求。

所以我的问题:

1)是否需要进行一些设置才能打开 NPH(或者前缀是否正确?)

2) cgi 应用程序可以进行一些测试来判断它是否真的处于 NPH 模式吗?

3) 是否打算将 stddout(即响应数据)实时传送到请求代理,还是 IIS 绝对必须首先以某种方式缓冲和解析它?

I am writing a prototype CGI application to run on an IIS 7.0 server, which will ultimately result in that application sending a number of http chunked responses that are generated in response to a query that may take some time to generate the actual data.

before delving into that side of things (ie generating the real data), i wanted to test if my cgi app is in fact running in non parsed header mode (ie the cgi app itself generates all headers, and IIS just returns all output to the requesting http browser/agent.

so i wrote a simple app that returns the following (note timetamps - there is a 1 second pause between each timestamped line, and as the text implies, this take just over 10 seconds to execute - you can in fact run the cgi app on the command line and observe this timing.

HTTP/1.1 200 OK
Date: Sun, 17 Jul 2011 09:07:47 GMT
Content-Type: text/plain
Transfer-Encoding: chunked

17;
NPH CGI Chunked Example

4D;
the fat cat sat on the mat, perplexed at the antics of the quick brown fox.

2D;
counting ... 1...  the time is now 09:07:48

2D;
counting ... 2...  the time is now 09:07:49

2D;
counting ... 3...  the time is now 09:07:50

2D;
counting ... 4...  the time is now 09:07:50

2D;
counting ... 5...  the time is now 09:07:51

2D;
counting ... 6...  the time is now 09:07:52

2D;
counting ... 7...  the time is now 09:07:53

2D;
counting ... 8...  the time is now 09:07:54

2D;
counting ... 9...  the time is now 09:07:55

2E;
counting ... 10...  the time is now 09:07:56

18;
NPH Chunked Example Ends

0

When I install the exe on the server and open it in internet explorer, the expected text is displayed (times differ as i ran them at a different time of day, and in different time zones):

NPH CGI Chunked Example
the fat cat sat on the mat, perplexed at the antics of the quick brown fox.
counting ... 1...  the time is now 16:14:58
counting ... 2...  the time is now 16:14:59
counting ... 3...  the time is now 16:15:00
counting ... 4...  the time is now 16:15:01
counting ... 5...  the time is now 16:15:02
counting ... 6...  the time is now 16:15:03
counting ... 7...  the time is now 16:15:04
counting ... 8...  the time is now 16:15:05
counting ... 9...  the time is now 16:15:06
counting ... 10...  the time is now 16:15:07
NPH Chunked Example Ends

HOWEVER - nothing is displayed until after the entire 10 seconds has elapsed.
(note - same result in chrome)

to make sure, i crafted a http request in a text editor and pasted it into telnet on port 80 to the server, and observed a 10 second gap before the entire response as shown above.

I get the same result, regardless of wether the exe has the prefix "nph-" or not - i performed the same test in telnet, with "nph-hello.exe", "nphhello.exe" and "hello.exe", using the following:

(note:identifying addresses are adjusted for this post)

GET /cgi-bin/nph-hello.exe HTTP/1.0
Host: www.myserver.com:80
From: [email protected]
User-Agent: telnet/1.0

(for relevance of exe naming prefix, read the notes at http://support.microsoft.com/default.aspx?scid=kb;EN-US;q176113 under "Resolution" beginning "as a workaround...")

I do not appear to observe any discernible output difference in telnet relating to the exe name prefix which leads me to believe this information is either out of date, or that something else needs to be enabled to turn on this feature, which clearly needs to happen before the cgi app is started - which explains why the prefix is used as opposed to something the app itself does - ie IIS needs to know wether to wait for a response)

whilst on the surface, it is achieving the desired result - the data finds it's way to the requesting http agent - i would prefer it to happen in real time, so progress updates can be displayed as the request is made.

so my questions:

1) is there some setting that needs to be made to turn on NPH (or is the prefix correct?)

2) is there some test the cgi app can make to tell if it is really in NPH mode?

3) is it intended that stddout (ie response data) be piped to the requesting agent in real time, or does IIS absolutely have to buffer and parse it in some way first?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文