gabordemooij / redbean

ORM layer that creates models, config and database on the fly
https://www.redbeanphp.com
2.31k stars 279 forks source link

Segmentation Fault #86

Closed j-hernandez closed 13 years ago

j-hernandez commented 13 years ago

2 classes:

class Model_User extends RedBean_SimpleModel
{
 public function get_issues()
 {
  $issues = R::find('issue', 'created_by_id = ? ORDER BY updated_at DESC LIMIT 2', array($this->id));
 }
}

class Model_Issue extends RedBean_SimpleModel
{
  //public function open()
 //{
     //setMeta stuff, using some R::getCell queries in defined methods to set properties 
    //I've commented everything out right now
  }
}

I've tried upping the limit (originally 128M) to 512M in php.ini because initially it was throwing allocated memory exhaustion errors in the logs and tossing up 500 pages.

If I modify the open() function in Model_User above and set the limit to 1, it works fine. As soon as I try to get more than 1 record, I get a segmentation fault (11) in my logs and a dead site. The weird thing is, I made some changes (mostly costmetic) and the code worked fine, then on the next page load, nothing. Haven't been able to get it working since. Really hindering, just going to go back to straight queries.

There's nothing special about my install, I'm in a dev environment running on an Ubuntu VM with 512MB RAM. I'm not asking the scripts to do a lot. Not sure where the hangup is. Will try to get some more info.

j-hernandez commented 13 years ago

I knocked the memory limit back down to 128M in php.ini. Loading the page that calls those classes (with LIMIT 2): [Tue Sep 20 13:14:34 2011] [error] [client 192.168.1.40] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 261900 bytes) in /var/www/apps/include/rb.php on line 343

gabordemooij commented 13 years ago

I guess this means that somehow this causes a recursive load action. I.E. your open() function causes the bean to load again which calls the open function etc etc

FYI; tested the code above and that just works.

j-hernandez commented 13 years ago

Its strange though - even after emptying the open() function, I was still receiving the error. Since you're unable to duplicate the issue I'll close it out - perhaps I just needed a break from the keyboard!

gabordemooij commented 13 years ago

Cant you send me the exact code that causes the error? Then I can investigate the issue for you...

Verstuurd vanaf mijn iPhone

Op 23 sep. 2011 om 14:48 heeft j-hernandezreply@reply.github.com het volgende geschreven:

Its strange though - even after emptying the open() function, I was still receiving the error. Since you're unable to duplicate the issue I'll close it out - perhaps I just needed a break from the keyboard!

Reply to this email directly or view it on GitHub: https://github.com/gabordemooij/redbean/issues/86#issuecomment-2178198

RankoR commented 10 years ago

I have the same issue on RB 1.5.4 with this code:

public function getQuote()
{
   return R::findOne("quote", "posted = ? ", array(false));
}

The quote table has about 50000 records. Bean initialization example:

                $quote->qid = $id;
                $quote->rating = $rating;
                $quote->text = $text;
                $quote->posted = false;
gabordemooij commented 10 years ago

Have you tried adding 'LIMIT 1' ?

RankoR commented 10 years ago

Thanks, it works with 'LIMIT 1'. But I suggest that "LIMIT 1" should be added to "findOne" method by default, shouldn't it? :)

zewa666 commented 10 years ago

Do you work in frozen mode? Would be interesting to know if this bug occurs in both situations

gabordemooij commented 10 years ago

Unfortunately adding ' LIMIT 1 ' is almost impossible. RedBeanPHP supports a lot of DB platforms and the LIMIT-statement is not an SQL standard. Also RedBeanPHP has a policy not to touch queries. Instead it allows you to inject snippets, but nothing more. Thanks for the suggestion anyway. I appreciate the feedback. Hopefully we can figure out what causes these issues.