AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 120489
Accepted
John
John
Asked: 2010-03-09 12:59:19 +0800 CST2010-03-09 12:59:19 +0800 CST 2010-03-09 12:59:19 +0800 CST

如何对导致分段错误的 PHP 脚本进行故障排除?

  • 772

我也在 stackoverflow.com 上发布了这个,因为我不确定这是编程问题还是服务器问题。我正在使用 ubuntu 9.10、apache2、mysql5 和 php5。

我注意到我的一些 php 程序有一个不寻常的问题。有时当访问像 profile.edit.php 这样的页面时,浏览器会抛出一个对话框,要求下载 profile.edit.php 页面。当我下载它时,文件中没有任何内容。profile.edit.php 应该是一个编辑用户信息的网络表单。

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

[Mon Mar 08 15:40:10 2010] [notice] child pid 480 exit signal Segmentation fault (11)

而且,问题可能会出现也可能不会出现,这取决于我部署应用程序的服务器。

附加细节 虽然这并不总是发生。它只是偶尔发生。例如,profile.edit.php 将正确加载。但只要我点击保存按钮(表单 action="profile.edit.php?save=true"),页面就会要求我下载 profile.edit.php。会不会是我的 php 脚本有时会消耗太多资源?

示例代码

保存操作后,我的 profile.edit.php 包含一个 data_access_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_access_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;
}
php apache-2.2 segmentation-fault
  • 1 1 个回答
  • 1936 Views

1 个回答

  • Voted
  1. Best Answer
    Kornel
    2010-03-09T14:41:40+08:002010-03-09T14:41:40+08:00

    由于无限递归,PHP 通常会出现段错误。如果是这种情况(尽管我在您发布的代码中没有看到任何内容),然后安装 XDebug 扩展,它添加了安全递归限制并会发出正常错误。

    否则它可能是 PHP 本身的错误。尝试更新版本(您会在snaps.php.net上找到最先进的版本)

    • 2

相关问题

  • 如何强制我的网址始终以 www 开头?

  • 在 Linux Xen VPS 上优化 Apache 和 MySQL

  • mod_rewrite 不转发 GET 参数

  • 更改 PHP 的默认配置设置?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    从 IP 地址解析主机名

    • 8 个回答
  • Marko Smith

    如何按大小对 du -h 输出进行排序

    • 30 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    MikeN 在 Nginx 中,如何在维护子域的同时将所有 http 请求重写为 https? 2009-09-22 06:04:43 +0800 CST
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    0x89 bash中的双方括号和单方括号有什么区别? 2009-08-10 13:11:51 +0800 CST
  • Martin Hope
    Kyle Brandt IPv4 子网如何工作? 2009-08-05 06:05:31 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve