PHP脚本导致分段错误,然后浏览器要求我下载没有任何内容的.PHP文件?

PHP脚本导致分段错误,然后浏览器要求我下载没有任何内容的.PHP文件?,php,segmentation-fault,Php,Segmentation Fault,我注意到我的一些php程序有一个不寻常的问题。有时,当访问profile.edit.php这样的页面时,浏览器会弹出一个对话框,要求下载profile.edit.php页面。当我下载它时,文件里什么都没有。php应该是一个编辑用户信息的web表单 我在其他一些php页面上也注意到了这一点。我查看apache错误日志,看到一条分段错误消息: [Mon Mar 08 15:40:10 2010] [notice] child pid 480 exit signal Segmentation faul

我注意到我的一些php程序有一个不寻常的问题。有时,当访问profile.edit.php这样的页面时,浏览器会弹出一个对话框,要求下载profile.edit.php页面。当我下载它时,文件里什么都没有。php应该是一个编辑用户信息的web表单

我在其他一些php页面上也注意到了这一点。我查看apache错误日志,看到一条分段错误消息:

[Mon Mar 08 15:40:10 2010] [notice] child pid 480 exit signal Segmentation fault (11)
此外,问题可能会出现,也可能不会出现,这取决于我部署应用程序的服务器

附加细节 但这种情况并非总是发生。这只是偶尔发生。例如,profile.edit.php将正确加载。但只要我点击save按钮(form action=“profile.edit.php?save=true”),页面就会要求我下载profile.edit.php。是不是有时候我的php脚本消耗了太多的资源

示例代码

保存操作后,my profile.edit.php包含一个data\u access\u object.php文件。我将data_access_object.php中的代码跟踪到这一行

 if($params[$this->primaryKey])
 {
                        $q = "UPDATE $this->tableName SET ".implode(', ', $fields)." WHERE ".$this->primaryKey." = ?$this->primaryKey";
                        $this->bind($this->primaryKey, $params[$this->primaryKey], $this->tblFields[$this->primaryKey]['mysqlitype']);
}
 else
{
$q = "INSERT $this->tableName SET ".implode(', ', $fields);
}
// Code executes perfectly up to this point
// echo 'print this'; exit; // if i uncomment this line, profile.edit.php will actually show 'print this'.  If I leave it commented, the browser will ask me to download profile.edit.php
if(!$this->execute($q)){ $this->errorSave = -3; return false;}
// When I jumped into the function execute(), every line executed as expected, right up to the return statement.  
如果有帮助,下面是data\u access\u object.php中的函数execute($sql)

function execute($sql)
{

        // find all list types and explode them
        // eg. turn ?listId into ?listId0,?listId1,?listId2 
        $arrListParam = array_bubble_up('arrayName', $this->arrBind);

        foreach($arrListParam as $listName)
           if($listName)
           {
                $explodeParam = array();
                $arrList = $this->arrBind[$listName]['value'];
                foreach($arrList as $key=>$val)
                {
                        $newParamName = $listName.$key;
                        $this->bind($newParamName,$val,$this->arrBind[$listName]['type']);
                        $explodeParam[] = '?'.$newParamName;
                }
                $sql = str_replace("?$listName", implode(',',$explodeParam), $sql);
           }

        // replace all ?varName with ? for syntax compliance
        $sqlParsed = preg_replace('/\?[\w\d_\.]+/', '?', $sql);
        $this->stmt->prepare($sqlParsed);

        // grab all the parameters from the sql to create bind conditions
        preg_match_all('/\?[\w\d_\.]+/', $sql, $matches);
        $matches = $matches[0];

        // store bind conditions
        $types = ''; $params = array();
        foreach($matches as $paramName)
        {
                $types .= $this->arrBind[str_replace('?', '', $paramName)]['type'];
                $params[] = $this->arrBind[str_replace('?', '', $paramName)]['value'];
        }

        $input = array('types'=>$types) + $params;



        // bind it
        if(!empty($types))
        call_user_func_array(array($this->stmt, 'bind_param'), $input);

        $stat = $this->stmt->execute();
        if($GLOBALS['DEBUG_SQL'])
                echo '<p style="font-weight:bold;">SQL error after execution:</p> ' . $this->stmt->error.'<p>&nbsp;</p>';

        $this->arrBind = array();
        return $stat;
}
函数执行($sql)
{
//找到所有列表类型并分解它们
//例如,将listId转换为listId0、listId1、listId2
$arrListParam=array\u bubble\u up('arrayName',$this->arrBind);
foreach($arrListParam作为$listName)
如果($listName)
{
$explodeParam=array();
$arrList=$this->arrBind[$listName]['value'];
foreach($arrlistas$key=>$val)
{
$newParamName=$listName.$key;
$this->bind($newParamName,$val,$this->arrBind[$listName]['type']);
$explodeParam[]='?'。$newParamName;
}
$sql=str_replace(“?$listName”,内爆(“,”,$explodeParam),$sql);
}
//将所有?varName替换为?以符合语法要求
$sqlParsed=preg\u replace(“/\?[\w\d\u\.]+/”,“?”,$sql);
$this->stmt->prepare($sqlParsed);
//从sql中获取所有参数以创建绑定条件
preg\u match\u all('/\?[\w\d\u\.]+/',$sql,$matches);
$matches=$matches[0];
//存储绑定条件
$types='';$params=array();
foreach($匹配为$paramName)
{
$types.=$this->arrBind[str_replace('?','',$paramName)]['type'];
$params[]=$this->arrBind[str_replace('?','$paramName)]['value'];
}
$input=数组('types'=>$types)+$params;
//绑起来
如果(!空($types))
调用_user_func_数组(数组($this->stmt,'bind_param'),$input);
$stat=$this->stmt->execute();
if($GLOBALS['DEBUG_SQL']))
执行后回显“

SQL错误:

”。$this->stmt->error。“

”; $this->arrBind=array(); 返回$stat; }
这可能是由于服务器配置不正确造成的。服务器直接发送文件,而不是将其解释为PHP程序。由于您使用的是Apache,以下配置设置()应该可以解决此问题:

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

SetHandler应用程序/x-httpd-php

编辑:似乎存在更深层次的问题。请参阅此答案和原始问题下的注释。

这通常意味着您没有在服务器上正确安装或配置PHP。

我认为应该这样做 httpd.conf中的AddType应用程序/x-httpd-php.php.phtml

我保存我的答案是因为这是一个修复程序,但他的真正问题是在HTML表单中使用“action”。 表格应为:

<form action="myphpfile.php" method="get">
  <input type="hidden" name="save" value="true" />
  First name: <input type="text" name="firstname" /><br />
  Last name: <input type="text" name="lastname" /><br />
  <input type="submit" value="Submit" />
</form>
INSERT INTO some_table SET field1='value 1', field2='value 2', field3='value 3'

名字:
姓氏:

在放置隐藏输入的表单操作中不使用查询。我想这就是为什么它会出现断层。如果要保存数据,我不会使用“get”作为应该使用“post”的方法。实际上,我一直都在使用“post”。

另外,要注意浏览器缓存。即使应用了正确的设置和正确的文件处理程序,浏览器仍会提示下载文件。
可以通过重新启动浏览器/清空浏览器缓存来解决此问题。

生成的最终SQL语句是什么样子的?如果您有:

// echo 'print this'; exit; 
如果您将其更改为:

echo "Query: $q";
exit;
并在你的问题中公布结果

据我所知,您的查询如下所示:

INSERT some_table SET field1, field2, field3
何时应该:

<form action="myphpfile.php" method="get">
  <input type="hidden" name="save" value="true" />
  First name: <input type="text" name="firstname" /><br />
  Last name: <input type="text" name="lastname" /><br />
  <input type="submit" value="Submit" />
</form>
INSERT INTO some_table SET field1='value 1', field2='value 2', field3='value 3'
如果您的时间小于运行脚本所需的时间,则可能发生这种情况

当达到Apache超时时,Apache将关闭连接。浏览器会看到连接完全关闭,但没有任何内容,因此无法识别如何处理它,因此会返回到未识别内容的默认行为,询问您是否要保存文件

取消“print this”echo语句的注释并退出会将一些文本输出到浏览器,而不是进入长时间运行的过程。未达到Apache超时,并且浏览器具有默认情况下应该显示的内容

如果脚本在处理时间上发生变化,只是偶尔超过apache超时,则可以解释偶尔发生的情况。或者你的脚本在某个地方被阻塞了


如果脚本超时总是低于apache超时,则会出现信息更丰富的“致命错误:最大执行时间…”错误。

如果PHP文件为空,服务器不会直接发送该文件。。。你说得对。从附加信息来看,这似乎是一个更深层次的问题。我应该根据删除这个答案吗?在meta上,这个问题投票率最高的答案的底线是“仅仅因为我