Page 1 of 1

My code keeps generating core.#### files

Posted: Tue May 19, 2009 5:02 am
by puke.nukem
Hi, I have a little web app I'm putting together and I've reached a wall. I have tried searching the forum for this kind of problem but I havn't found anything similar.
My apologies if this is a problem.

The following code (part of a larger program) keeps generating some werid core.454343 (random numbers) in my root.

Code: Select all

 
<div class='title'>Unpaid Invoices</div>
<?php
                $oi['id'] = 15;
                $i = new invoice();
                $i->loadInvoice($oi);
 ?>
 
The code that initialises the object is as follows:

Code: Select all

 
        public function loadInvoice($params)
        {
            $tmp = array();
            if(array_key_exists('invoice_id', $params))
            {
                $tmp = $this->switchId($params);
                $params = $tmp;
            } else {
                $tmp = $params;
                $params = null;
                $params['id'] = $tmp['id'];
            }
 
            $sql = "SELECT id, client_id, workorder_id, DATE_FORMAT(date_issued, '%d-%m-%y') AS date_issued, DATE_FORMAT(date_paid, '%d-%m-%y') AS date_paid, DATE_FORMAT(date_sent, '%d-%m-%y') AS date_sent, invoice_number FROM invoice WHERE id=:id";
            $result = databaseHandler::getRow($sql, $params);
            foreach($result as $key=>$string)
            {
                $this->invoice_details[$key] = $string;
            }
            $this->invoice_id_primary['id'] = $result['id'];
            $this->invoice_id_secondary['invoice_id'] = $result['id'];
        }
 
If someone can help me shed some light on this I would appreciate it. If you require some more code I can also provide it.

For the record this also happens when I instantiate a new client object from my cleint class. It is pretty much the same as the example above so I won't include that.

Thanks

Re: My code keeps generating core.#### files

Posted: Tue May 19, 2009 3:16 pm
by Darhazer
Do you have some file functions (fopen, file_put_contents) in your code? Maybe some debug info is written to those files?

Re: My code keeps generating core.#### files

Posted: Tue May 19, 2009 5:57 pm
by puke.nukem
@Darhazer: no, i don't have anything like that. Maybe I should try?

I have read online that the core.#### files are actually memory dumps of the crashing process. Apparently it is possible to open and view these files for debugging purposes, but I am unable to find any tutorial or instructions on how to do so on my Vista machine.

Odd Behaviour: Interestingly enough I've found that if I remove a specific function complete from my app (semail()) it will not genearte errors, yet if I try to leave the function header intact and remove it's contents entirely it will still generate the core files.

Re: My code keeps generating core.#### files

Posted: Tue May 19, 2009 7:38 pm
by puke.nukem
I have the following included php file

Code: Select all

 
    require_once("class.phpmailer.php");
 
    function pbody($id, $comment = null)
    {
        $message = "";
        $invoice = new invoice(); $invoice->loadInvoice($id);
        $client = new client();  $client->loadClientByInvoiceId($id);
        $invoice->getInvoiceItems($id);
        $invoice->addTotals();
        $invoice->getGSTOnTotal();
        include("lib/email/email-template.php");
        return $message;
    }
    function get_ccs($a){
        $ccs = array();
        $ccs = explode(",", $a);
 
        $values = array();
        foreach ($ccs as &$c)
        {
            $c = trim($c);
            array_push($values, $c);
        }
        return $ccs;
    }
    function semail($bdy, $destination_email, $subject, $cc = null, $bcc = null)
    {
        $ccs = array(); $bccs = array();
        if(!empty($cc)){$ccs = get_ccs($cc);}
        if(!empty($bcc)){$bccs = get_ccs($bcc);}
        $m = "<html><head><title>Invoice</title></head><body leftmargin='0' marginwidth='0' topmargin='0' marginheight='0' offset='0' bgcolor='#3399cc' >";
        $m .= $bdy;
        $m .= "</body></html>";
 
        //error_reporting(E_ALL);
        error_reporting(E_STRICT);
        date_default_timezone_set('America/Toronto');
        ////include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
        $mail = new PHPMailer();
        $mail->IsSMTP();
        $mail->SMTPAuth = true;
        $mail->SMTPSecure= "tls";
        $mail->Host= "smtp.gmail.com";
        $mail->Port= 587;
        $mail->Username= "me@mydomain.com";
        $mail->Password= "mypass";
        $mail->AddReplyTo("reply@mydomain.com");
        $mail->From= "mw@mydomain.com";
        $mail->FromName= "My Name";
        $mail->Subject= $subject;
        $mail->Body= "Hi,This is the HTML BODY";
        $mail->AltBody= "To view the message, please use an HTML compatible email viewer!";
        $mail->WordWrap= 50;
        $mail->MsgHTML($m);
        $mail->AddAddress($destination_email);
 
        if(!empty($ccs))
        {
            foreach($ccs as $c)
            {$mail->AddCC($c);}
            }
        if(!empty($bccs))
        {foreach($bccs as $b)
            {$mail->AddBCC($b);}
        }
        $mail->IsHTML(true);
        $mail_sent = false;
        if(!$mail->Send()) {
            echo "Mailer Error: " . $mail->ErrorInfo;
            $mail_sent = false;}
        else {
            $mail_sent = true;
            }
        return $mail_sent;
    }
 
Now, if I arbitrarily remove any of the functions from that included php file the core generation stops. If, once any function is removed, I try to add another random function (that is never used, empty, and affects nothing) the app crashes and generates the cores again!

I am still very confused as to why this would occur.

Has anyone had any experiences like this before?

Re: My code keeps generating core.#### files

Posted: Tue May 19, 2009 10:23 pm
by puke.nukem
I've created an entirely new class "notes"

Code: Select all

 
<?php
    class note
    {
        public $note_id_primary = array();
        public $note_id_secondary = array();
        public $note_details = array();
 
        public function loadNote($id)
        {
         if(is_array($id))
         {
            if(array_key_exists('note_id', $id))
            {
                $new_array['id'] = $id['note_id'];
                 unset($id);
                $id = $new_array;
            } else {
                $tmp = $id;
                unset($id);
                $id['id'] = $tmp['id'];
            }
         } else {
             $tmp = $id;
             unset($id);
            $id['id'] = $tmp;
         }
 
            $sql = 'SELECT * FROM notes WHERE id=:id';
            $result = databaseHandler::getRow($sql, $id);
 
            foreach($result as $key =>$string)
            {
                $this->note_details[$key] = $string;
            }
 
            $this->note_id_primary['id'] = $id['id'];
            $this->note_id_secondary['note_id'] = $id['id'];
        }
 
        public function addNote($params){
            $params['date'] = $this->dateForMysql($params['date']);
            $sql = 'INSERT INTO notes (title, body, author, timestamp, type) VALUES(:title, :body, :author, NOW(), :type)';
            $this->workorder_id_primary['id'] =  databaseHandler::executeQuery($sql, $params);
            $workorder_id_secondary['workorder_id'] = $this->workorder_id_primary['id'];
            return $this->workorder_id_primary['id'];
        }
 
        public function updateNote($params){
            $params['date'] = $this->dateForMysql($params['date']);
            $sql = "UPDATE notes SET title=:title, body=:body, author=:author, update_date= NOW(), updated_by=:updated_by WHERE id=:id";
            databaseHandler::executeQuery($sql, $params);
            $this->clearParams();
            $this->note_id_primary['id'] = $params['id'];
            $this->note_id_secondary['note_id'] = $params['id'];
            $this->loadNote($this->note_id_primary);
 
         }
 
        private function dateForMysql($date){
            $pieces = explode("-", $date);
            $dateForMysql = $pieces[2] . "-" . $pieces[1] . "-" .$pieces[0];
            return $dateForMysql;
        }
    } // end class
?>
 
and if I remove the functions there is no problem, yet if I add them the core dumps are created again. :banghead:

Re: My code keeps generating core.#### files

Posted: Wed May 20, 2009 7:52 am
by Benjamin
http://gallery.menalto.com/node/59479 Just search around a while.

Re: My code keeps generating core.#### files

Posted: Sat May 23, 2009 10:51 pm
by puke.nukem
Hi I have seemed to have solved this problem, although I'm not 100% sure how.

For anyone who may be experiencing something similar I'll just explain what I did.

Having reached extreme frustration I manually retyped all the code, and created fresh .php files, from the files that were generating the core dumps.
I then reuploaded the files to my server exactly how it was previously. At that point everything worked like a charm and considerably faster.

I'm not sure what happened exactly but I suspect that there may have been some encoding corruption with those files at some point.

Anyway, thanks to all you guys that helped out this was very much appreciated.