在 C# 应用程序中使用 FastCGI 应用程序
我正在用 C# 开发一个小型网络服务器,作为一个较大项目的一部分(该项目的性质阻止我使用像 apache nginx 这样的东西,这将是我的第一选择)。
Web 服务器需要 PHP 来处理它收到的一些请求。
目前,我正在使用 System.Diagnostics.Process 并将 php 作为 cgi 运行,并通过管道传输数据。这可以工作,但速度相当慢(大概是 PHP 从头开始的开销,这是主要问题)。所以我想尝试使用FastCGI。
我查看了 FastCGI 规范,并开始实现一个基本子集,但运气不佳。 我见过的大多数示例都是用于开发 FastCGI 模块的库,而不是用于调用它们的库,因此我几乎没有什么可以用作参考。
有没有人有在 .NET 下执行此操作的经验,或者可以为此类项目推荐任何有用的资源?
I'm developing a small webserver in C# as part of a larger project (the nature of the project prevents me from using something like apache nginx, which would be my first choice).
The webserver needs PHP to process some of the requests it recieves.
At the moment I'm running php as a cgi using System.Diagnostics.Process and piping data to and from. This works but is pretty slow (presumably from the overhead from PHP start starting from scratch, is the main issue). So I want to try using FastCGI instead.
I've looked at the FastCGI spec, and made a start at implementing a basic subset, but haven't have much luck.
Most of of the examples I've seen have been libraries for developing FastCGI modules, not for invoking them, so I've had very little to use as reference.
Has any one got any experience of doing this under .NET, or could recommend any useful resources for this kind of project?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也必须做类似的事情(在过渡期间)并使用 MiniHttpd:一个 HTTP Web 服务器库。我必须做的事情略有不同,因为我不需要 httpd,而是需要一种从 C# 应用程序执行 PHP 的方法。
它基本上使用磁盘上的文件直接引用 DLL 中的非托管代码(请参阅 PhpAppDirectory.cs)。
I also had to do something similar (during a transition period) and used MiniHttpd: an HTTP web server library. What I had to do was slightly different as I didn't need an httpd rather a way of executing PHP from a C# application.
It basically references the unmanaged code straight out of the DLL using the file on disk (see PhpAppDirectory.cs).
我必须做同样的事情,它真的很容易做,
如果你只是用cmd运行php-cgi exe和一个测试php文件,你会看到它的输出
这是我的例子,你需要做的就是调用php-cgi并在响应中读取
第一个双中断是标头停止和输出发生的位置,因此如果您的控制台输出位于变量 EG
public string phpOutput
中,那么您只需要一个正则表达式将其拆分为 \ n\n 但将计数设置为 1,以便仅在第一次出现 \n\n,EG时分割
I have had to do the same thing its really easy to do,
If you just run the php-cgi exe with cmd and a test php file you will see it output
That is my example above all you need to do is call php-cgi and read in the response
The first double break is where your headers stop and your output occurs so if you have your console output in a variable E.G
public string phpOutput
then you just need a regex to split it on \n\n but set the count to 1 so it only splits on the first occurrence of \n\n,E.G