dongtui0650 2012-01-08 13:43
浏览 105
已采纳

C#PHP-CGI - 调用phpinfo崩溃了webserver

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?

  • 写回答

1条回答 默认 最新

  • duanhe3393 2012-01-09 07:16
    关注

    The problem is that the StandardOutput has a certain buffer size. If this buffer is full then any write() to stdout will block. Now if you call p.WaitForExit() you are waiting indefinitely.

    The solution is to first read everything from the StandardOutput and then call WaitForExit.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集