Randomly segmentation faults

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
piccoloprincipe
Forum Newbie
Posts: 12
Joined: Wed Jan 16, 2008 4:11 pm

Randomly segmentation faults

Post by piccoloprincipe »

As you can see here:
http://piccoloprincipe.homelinux.com/suite/ (home server, might be offline every now and then)
Php has started to produce crashes on certain pages. The weird things is that something produce a segmentation fault after a bit of time or byte... In the page I simply repeat var_dump("A") for 10000 times and php dies...
Other pages doesn't work, other are generated before the crash occurs and are full functional.
Has anyone experienced this problem? How can i debug my code and find what causes the segfault?
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Re: Randomly segmentation faults

Post by Ambush Commander »

Not segfaulting for me?
piccoloprincipe
Forum Newbie
Posts: 12
Joined: Wed Jan 16, 2008 4:11 pm

Re: Randomly segmentation faults

Post by piccoloprincipe »

The apache log said the child process has caused segmentation fault... Once for every time I load the page.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Re: Randomly segmentation faults

Post by Maugrim_The_Reaper »

What version of PHP are you using?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Randomly segmentation faults

Post by VladSun »

Maybe strace could help?
There are 10 types of people in this world, those who understand binary and those who don't
piccoloprincipe
Forum Newbie
Posts: 12
Joined: Wed Jan 16, 2008 4:11 pm

Re: Randomly segmentation faults

Post by piccoloprincipe »

I have fixed the problem, I redefined the constructor from php4 to php5.
That was

Code: Select all

 
class OtkRecord
{
    function _construct(...)
    //mantained for compatibility
    function OtkRecord(...)
    {
        $this->__construct(...);           (A)
    }
}
class OtkForum extends OtkRecord
{
    function __construct(...)
    {
         parent::OtkRecord(...);            (B)
    }
}
 
So on creation of an object of OtkForum, B calls A that calls B (instead of __construct of OtkRecord) that calls A that calls B... and php segfaulted.
Now I have deleted the old php4-style constructor and everything is fine.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Re: Randomly segmentation faults

Post by Ambush Commander »

I tested a slightly modified version and discovered that the setup recurses infinitely:

Code: Select all

<?php
class OtkRecord
{
    function __construct() {}
    //mantained for compatibility
    function OtkRecord()
    {
        $this->__construct();
    }
}
class OtkForum extends OtkRecord
{
    function __construct()
    {
         parent::OtkRecord();
    }
}
 
new OtkForum();
What's happening is OtkRecord is calling __construct, but the OtkForum implementation is being used, not the empty OtkRecord one. Thus, infinite recursion.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Re: Randomly segmentation faults

Post by Jenk »

Try this:

Code: Select all

<?php
class OtkRecord
{
    function __construct() {}
    //mantained for compatibility
    function OtkRecord()
    {
 
    }
}
class OtkForum extends OtkRecord
{
    function __construct()
    {
        $reflect = new ReflectionClass($this);
        $reflect = $reflect->getParentClass()->getConstructor()->getName();
        parent::$reflect();
    }
}
 
new OtkForum();
piccoloprincipe
Forum Newbie
Posts: 12
Joined: Wed Jan 16, 2008 4:11 pm

Re: Randomly segmentation faults

Post by piccoloprincipe »

I have simply delete the old constructor, I don't need to support php4 anymore.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Randomly segmentation faults

Post by Chris Corbyn »

:arrow: Moved to PHP Code
Post Reply