Randomly segmentation faults
Moderator: General Moderators
-
piccoloprincipe
- Forum Newbie
- Posts: 12
- Joined: Wed Jan 16, 2008 4:11 pm
Randomly segmentation faults
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?
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?
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
Re: Randomly segmentation faults
Not segfaulting for me?
-
piccoloprincipe
- Forum Newbie
- Posts: 12
- Joined: Wed Jan 16, 2008 4:11 pm
Re: Randomly segmentation faults
The apache log said the child process has caused segmentation fault... Once for every time I load the page.
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
Re: Randomly segmentation faults
What version of PHP are you using?
Re: Randomly segmentation faults
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
I have fixed the problem, I redefined the constructor from php4 to php5.
That was
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.
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)
}
}
Now I have deleted the old php4-style constructor and everything is fine.
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
Re: Randomly segmentation faults
I tested a slightly modified version and discovered that the setup recurses infinitely:
What's happening is OtkRecord is calling __construct, but the OtkForum implementation is being used, not the empty OtkRecord one. Thus, infinite recursion.
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();Re: Randomly segmentation faults
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
I have simply delete the old constructor, I don't need to support php4 anymore.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia