我贴在stackoverflow.com以及因为我不知道这是一个编程问题或服务器问题。 我使用的是Ubuntu 9.10,apache2,mysql5和php5。
我注意到我的一些PHP程序有一个不寻常的问题。 有时在浏览profile.edit.php等页面时,浏览器会popup一个对话框,要求下载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)
而且,这个问题可能会也可能不会出现,取决于我在哪个服务器上部署我的应用程序。
更多详细信息这不会一直发生。 它只发生有时。 例如,profile.edit.php将正确加载。 但只要我点击保存button(表单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> </p>'; $this->arrBind = array(); return $stat; }
PHP通常会由于无限recursion而发生段错误。 如果是这种情况(虽然我没有看到你已经发布的代码),然后安装XDebug扩展,它增加了安全的recursion限制,并会发出正常的错误。
否则,它可能是PHP本身的错误。 尝试更新的版本(你会发现在snaps.php.net尖端的一个)