Out of memory error in Laravel 5.3

2019-06-11 03:10发布

There is an issue on Laravel 5.3 / Jesenger / MongoDB 3.0 which I reported here. The issue arises from saving or updating a field with special characters like "°ó" in mongodb, it always results in "out of memory" error.

Allowed memory size of ######### bytes exhausted (tried to allocate ********** bytes) 
//Whereas ######### is always greater than **********

My question is how can I convert the special character so that they can be safely pushed into the database. Note: I am doing batch insert and updating of like 30000 records, a good solution may put this into consideration.

// Code Sample
<?php 
class Products extends Jessenger\Mongodb\Eloquent\Model
{

}
?>
$product = new Products();
$product->name = 'Akara';
$product->sku = 'naija001';
$product->description = 'special characters like °ó in mongodb';
$product->save(); // Throws allowed memory size of 1392394984 bytes 
                  // exhausted (tried to allocate 2195914) note that 
                  // allowed memory size is greater than the allocated size

My temporal fix

$product = new Products();
$product->name = 'Akara';
$product->sku = 'naija001';
$product->description = utf8_encode('special characters like °ó in mongodb');
$product->save(); // Saved successfully

0条回答
登录 后发表回答