Error when total field in table is 28

67 views
Skip to first unread message

Kenny

unread,
May 18, 2012, 12:27:46 PM5/18/12
to redbeanphp
After i add a new field DATETIME (Y-m-d H:i:s), the second run it
always shows memory exhausted. The table has 28 columns (including the
"id" column). When it was only 27 columns, it did not show error.

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried
to allocate 43 bytes) in /include/rb.php on line 4836

Darryl Hebbes

unread,
Mar 19, 2013, 10:10:16 AM3/19/13
to redbe...@googlegroups.com
Hi,

Did you manage to solve this problem?

I am having the same issue.

Regards,
D

gabor

unread,
Mar 19, 2013, 2:58:37 PM3/19/13
to redbe...@googlegroups.com

Hi

Tested this but this script seems to work:

$bean = R::dispense('bean');
for($i=0; $i<100; $i++) $bean->{'prop'.$i} = R::isoDateTime();
$id = R::store($bean);
print_r(R::load('bean',$id));

can you send me a code example (which I can run directly from CLI) that demonstrates the problem?

Darryl Hebbes

unread,
Mar 19, 2013, 3:10:32 PM3/19/13
to redbe...@googlegroups.com
Hi,

Sorry not sure how to get it working in CLI but this code causes the memory error. The R::find() is searching through 40000 records.
I fixed it by adding a limit to 100.

require('rb.php'); //  ver3.4
R::setup('mysql:host=localhost; dbname=abc','root','toor');
R::freeze( true );
$bb = "paid";
$table = "ltorderdetails";
$nextSTDTicket = R::find($table, "product_code=1 AND status_ticket=? order by redeem_code desc", array($bb));


Hope that assists.

Darryl Hebbes

unread,
Mar 19, 2013, 3:14:41 PM3/19/13
to redbe...@googlegroups.com
And sorry I also did override the php.ini "memory limit" with this solution http://stackoverflow.com/a/13749459

I had set the MEMORY_LIMIT to 128MB before I used the override.

D
Message has been deleted

gabor

unread,
Mar 19, 2013, 3:31:03 PM3/19/13
to redbe...@googlegroups.com
That query does not look strange.
I run 20000 unit tests with RedBeanPHP without having this issue.
Could be the PHP version, what version of PHP are you running?
Can you send me a script that creates a DB with the same size you have so I can test it?

Darryl Hebbes

unread,
Mar 19, 2013, 4:44:45 PM3/19/13
to redbe...@googlegroups.com
Hi Gabor,

Sure, the script below will create the following error:
[19-Mar-2013 20:35:37 UTC] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 78 bytes) in /Applications/MAMP/htdocs/ltdsn_db_tests/rb-3-4.php on line 1321 

Full script and shows my system setup in comment:

<?php
// Uncomment to fix 
// ini_set('memory_limit', '-1');

/***

System:
PHP Version 5.4.4
MySQL Version 5.5.25
MAMP v2 
Mac OS X 10.7.5

***/


require('rb-3-4.php');
R::setup('mysql:host=localhost; dbname=XXX','root','root');
R::freeze( false );

function CreateTickets()
{

$shop_range_standard = range(10000, 29999);
$shop_range_reduced = range(30000, 39999);

R::begin();
try {

$order = R::dispense('ltorders');
$order->order_number = 1;
$order->order_date = R::isoDateTime();
$order->perpost_jn = false;
$order->status = 'active';
$order->comments = 'Internal bulk insert for organisations';
$order->customer_id = 2;  // hard coded 
$orderid = R::store($order);

   foreach ($shop_range_standard as $number) {
            $orderdetails = R::dispense('ltorderdetails');
  $orderdetails->order_number = $orderid;  // related to order id
$orderdetails->gast_titel = "";
$orderdetails->gast_vorname = "";
$orderdetails->gast_name = "";
$orderdetails->redeem_code = $number;
$orderdetails->product_code = 1;  // 
$orderdetails->status_ticket = "paid"; // confirmed,paid,validated
$orderdetails->status_booking = "";  // reserved
$id = R::store($orderdetails);
}

   foreach ($shop_range_ermaessigt as $number) {
            $orderdetails = R::dispense('ltorderdetails');
  $orderdetails->order_number = $orderid;  // related to order id
$orderdetails->gast_titel = "";
$orderdetails->gast_vorname = "";
$orderdetails->gast_name = "";
$orderdetails->redeem_code = $number;
$orderdetails->product_code = 2;  // 
$orderdetails->status_ticket = "paid"; // confirmed,paid,validated,
$orderdetails->status_booking = "";
$id = R::store($orderdetails);
}

R::commit();
echo "Done adding bulk orders";
} catch (Exception $e) {
   R::rollback();
   echo $e;
}

}

function findticketAction()
{
$bb = "paid";
$table = "ltorderdetails";
$nextSTDTicket = R::find($table, "status_ticket=? order by redeem_code desc", array($bb));

var_dump($nextSTDTicket);
}

CreateTickets();
findticketAction(); // Error called here


?>

gabor

unread,
Mar 20, 2013, 3:03:42 PM3/20/13
to redbe...@googlegroups.com


Hi,

Thanks for the script. I tried this and I ran out of memory as well.
Seems like you are trying to query 30000 beans which is too much for 128 MB of RAM.
You'll need to do this in batches.

- a plain php array takes 3 kb RAM
- a bean takes 8 kb RAM

I can reduce the bean size (by delaying the moment it creates a copy; a bean has a copy of itself to allow you to diff, that should reduce size with 3kb)

However if the number of rows is big enough you'll also run out of memory with plain PHP arrays; what we really need is an SQL cursor, however
RedBeanPHP currently does not support this.

If you really need to traverse the records and the situation is very urgent you can build a simple cursor yourself. Simply use the fetchObject() methods of PHP and manually convert the records to beans using the convertToBean() method. If you have any questions about this approach please let me know, could become a nice plugin for people working with big record sets.

Hope this helps.

Cheers,
Gabor
Reply all
Reply to author
Forward
0 new messages