Page 1 of 1
Randomly segmentation faults
Posted: Wed Jan 16, 2008 4:16 pm
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?
Re: Randomly segmentation faults
Posted: Wed Jan 16, 2008 8:03 pm
by Ambush Commander
Not segfaulting for me?
Re: Randomly segmentation faults
Posted: Thu Jan 17, 2008 1:40 am
by piccoloprincipe
The apache log said the child process has caused segmentation fault... Once for every time I load the page.
Re: Randomly segmentation faults
Posted: Thu Jan 17, 2008 4:14 am
by Maugrim_The_Reaper
What version of PHP are you using?
Re: Randomly segmentation faults
Posted: Thu Jan 17, 2008 5:42 am
by VladSun
Maybe strace could help?
Re: Randomly segmentation faults
Posted: Thu Jan 17, 2008 5:46 pm
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.
Re: Randomly segmentation faults
Posted: Thu Jan 17, 2008 5:51 pm
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.
Re: Randomly segmentation faults
Posted: Fri Jan 18, 2008 4:22 am
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();
Re: Randomly segmentation faults
Posted: Sun Jan 20, 2008 1:32 pm
by piccoloprincipe
I have simply delete the old constructor, I don't need to support php4 anymore.
Re: Randomly segmentation faults
Posted: Mon Jan 21, 2008 5:29 pm
by Chris Corbyn

Moved to PHP Code