Joh*_*ohn 5 php segmentation-fault
我注意到我的一些PHP程序有一个不寻常的问题.有时,当访问profile.edit.php这样的页面时,浏览器会抛出一个对话框,要求下载profile.edit.php页面.当我下载它时,文件中没有任何内容.profile.edit.php应该是一个编辑用户信息的Web表单.
我在其他一些php页面上也注意到了这一点.我查看了我的apache错误日志,并且看到了分段错误消息:
[Mon Mar 08 15:40:10 2010] [notice] child pid 480 exit signal Segmentation fault (11)
Run Code Online (Sandbox Code Playgroud)
此外,根据我部署应用程序的服务器,问题可能会出现也可能不会出现.
附加细节 这不会一直发生.它有时只会发生.例如,profile.edit.php将正确加载.但是只要我点击保存按钮(form 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.
Run Code Online (Sandbox Code Playgroud)
如果它有帮助,这里是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> </p>';
$this->arrBind = array();
return $stat;
}
Run Code Online (Sandbox Code Playgroud)
这可能是由于服务器配置不正确造成的。服务器直接发送文件,而不是将其解释为 PHP 程序。由于您使用的是 Apache,因此以下配置设置(来自此处)应该可以解决该问题:
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Run Code Online (Sandbox Code Playgroud)
编辑:似乎还有更深层次的问题。请参阅此答案和原始问题下的评论。