C# PHP-CGI - 调用 phpinfo 使网络服务器崩溃
我创建了一个简单且小型的网络服务器,仅用于处理 GET 请求。我还想添加 PHP 支持并对其进行管理。但有一个问题:
每次我尝试在 .php 文件中调用 phpinfo() 时,我的服务器都会停在“WaitForExit”进程上。
class FastPHP
{
private string _phpPath = @"C:\\Program Files (x86)\\PHP\\php-cgi.exe";
Process p;
public FastPHP(string filename)
{
p = new Process();
p.StartInfo.FileName = this._phpPath;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.Arguments = "-q \""+filename+"\"";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
}
public string getPHPOutput()
{
p.Start();
p.WaitForExit();
string sOutput = p.StandardOutput.ReadToEnd();
p.Close();
return sOutput;
}
}
我的 PHP.ini 设置应该没问题,我调整了所有内容以供 fastcgi 使用。有什么想法如何解决这个问题吗?
I created a simple and small webserver for only handling GET requests. I also wanted to add PHP support and also managed it. But there is one problem:
Everytime I try to call phpinfo() inside a .php file my server stops at "WaitForExit" Process.
class FastPHP
{
private string _phpPath = @"C:\\Program Files (x86)\\PHP\\php-cgi.exe";
Process p;
public FastPHP(string filename)
{
p = new Process();
p.StartInfo.FileName = this._phpPath;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.Arguments = "-q \""+filename+"\"";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
}
public string getPHPOutput()
{
p.Start();
p.WaitForExit();
string sOutput = p.StandardOutput.ReadToEnd();
p.Close();
return sOutput;
}
}
my PHP.ini settings should be fine, I adapted everything for fastcgi use. Any Ideas how to fix this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是
StandardOutput
具有一定的缓冲区大小。如果此缓冲区已满,则任何对 stdout 的 write() 都会阻塞。现在,如果您调用p.WaitForExit()
,您将无限期地等待。解决方案是首先从
StandardOutput
读取所有内容,然后调用WaitForExit
。The problem is that the
StandardOutput
has a certain buffer size. If this buffer is full then anywrite()
to stdout will block. Now if you callp.WaitForExit()
you are waiting indefinitely.The solution is to first read everything from the
StandardOutput
and then callWaitForExit
.