Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP script causes segmentation fault then the browser asks me to download the .php file with nothing in it?
    text
    copied!<p>I've noticed an unusual problem with some of my php programs. Sometimes when visiting a page like profile.edit.php, the browser throws a dialogue box asking to download profile.edit.php page. When I download it, there's nothing in the file. profile.edit.php is supposed to be a web form that edits user information.</p> <p>I've noticed this on some of my other php pages as well. I look in my apache error logs, and I see a segmentation fault message:</p> <pre><code>[Mon Mar 08 15:40:10 2010] [notice] child pid 480 exit signal Segmentation fault (11) </code></pre> <p>And also, the issue may or may not appear depending on which server I deploy my application too.</p> <p><strong>Additonal Details</strong> This doesn't happen all the time though. It only happens sometimes. For example, profile.edit.php will load properly. But as soon as I hit the save button (form action="profile.edit.php?save=true"), then the page asks me to download profile.edit.php. Could it be that sometimes my php scripts consume too much resources?</p> <p><strong>Sample code</strong></p> <p>Upon save action, my profile.edit.php includes a data_access_object.php file. I traced the code in data_access_object.php to this line here</p> <pre><code> if($params[$this-&gt;primaryKey]) { $q = "UPDATE $this-&gt;tableName SET ".implode(', ', $fields)." WHERE ".$this-&gt;primaryKey." = ?$this-&gt;primaryKey"; $this-&gt;bind($this-&gt;primaryKey, $params[$this-&gt;primaryKey], $this-&gt;tblFields[$this-&gt;primaryKey]['mysqlitype']); } else { $q = "INSERT $this-&gt;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-&gt;execute($q)){ $this-&gt;errorSave = -3; return false;} // When I jumped into the function execute(), every line executed as expected, right up to the return statement. </code></pre> <p>And if it helps, here's the function execute($sql) in data_access_object.php</p> <pre><code>function execute($sql) { // find all list types and explode them // eg. turn ?listId into ?listId0,?listId1,?listId2 $arrListParam = array_bubble_up('arrayName', $this-&gt;arrBind); foreach($arrListParam as $listName) if($listName) { $explodeParam = array(); $arrList = $this-&gt;arrBind[$listName]['value']; foreach($arrList as $key=&gt;$val) { $newParamName = $listName.$key; $this-&gt;bind($newParamName,$val,$this-&gt;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-&gt;stmt-&gt;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-&gt;arrBind[str_replace('?', '', $paramName)]['type']; $params[] = $this-&gt;arrBind[str_replace('?', '', $paramName)]['value']; } $input = array('types'=&gt;$types) + $params; // bind it if(!empty($types)) call_user_func_array(array($this-&gt;stmt, 'bind_param'), $input); $stat = $this-&gt;stmt-&gt;execute(); if($GLOBALS['DEBUG_SQL']) echo '&lt;p style="font-weight:bold;"&gt;SQL error after execution:&lt;/p&gt; ' . $this-&gt;stmt-&gt;error.'&lt;p&gt;&amp;nbsp;&lt;/p&gt;'; $this-&gt;arrBind = array(); return $stat; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload