I posted this on stackoverflow.com as well because I'm not sure if this is a programming problem or a server problem. I'm using ubuntu 9.10, apache2, mysql5 and php5.

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.

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:

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

And also, the issue may or may not appear depending on which server I deploy my application too.

Additonal Details 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?

Sample code

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

                        $q = "UPDATE $this->tableName SET ".implode(', ', $fields)." WHERE ".$this->primaryKey." = ?$this->primaryKey";
                        $this->bind($this->primaryKey, $params[$this->primaryKey], $this->tblFields[$this->primaryKey]['mysqlitype']);
$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.  

And if it helps, here's the function execute($sql) in data_access_object.php

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)
                $explodeParam = array();
                $arrList = $this->arrBind[$listName]['value'];
                foreach($arrList as $key=>$val)
                        $newParamName = $listName.$key;
                        $explodeParam[] = '?'.$newParamName;
                $sql = str_replace("?$listName", implode(',',$explodeParam), $sql);

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

        // 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
        call_user_func_array(array($this->stmt, 'bind_param'), $input);

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

        $this->arrBind = array();
        return $stat;
  • @johnlai2004 this belongs to stackoverflow perhaps? – c0mrade Mar 8 '10 at 21:03
  • I put it on stackoverflow as well, but can't tell if the segmentation fault is caused by a programming error or an apache configuration error. That's why I'm not sure which site it belongs to. – John Mar 8 '10 at 21:15
  • Cross posting generally is considered discouraged. stackoverflow.com/questions/2404237 – Zoredache Mar 8 '10 at 23:09
  • In my case it was eaccelerator faulting apache server. – user145824 Nov 16 '12 at 14:55

PHP usually segfaults because of infinite recursion. If that's the case (although I don't see any in the code you've posted), then install XDebug extension which adds safe recursion limit and will emit normal error.

Otherwise it may be bug in PHP itself. Try newer version (you'll find cutting-edge one on snaps.php.net)

  • +1 for it being some kind of PHP bug. Unfortunately I have ran into PHP bugs a few times. A segfault is a common symptom. – Zoredache Mar 8 '10 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.