need help with query in db with huge row

Posted 3 years ago by rehanskrill

i am writing an api for one of my project so i am facing php error my table as around 900K row method :1 my code

$products = Product::where('buyer', 0)->where('cat_id', 1)->get();
$keyby = $products->keyBy('product_id');
$keyby->all();
 $datas= gzcompress($keyby);
$params = base64_encode($this->_fnEncrypt($datas, $this->user->key));
//data will be encrypted with user key and wii send to request url by curl
// optional $result = $this->_sendRequest(['data' => $params]);

when i use method one i always get this type error i put memory_limit to 5GB but always same

PHP Fatal error: Out of memory (allocated 1705771008) (tried to allocate 2 bytes)

method 2:

Product::where('buyer', 0)->where('cat_id',1)->chunk(10000, function($products) {   
 $keyby= $products->keyBy('product_id');
//$keyby->all();
});
//but it will chunk 10000 row at once i need to get all rows then i need to encrypt them.

is there anyway to collect all data by my query then encrypt them. and every row should in in key by product_id with json encrypted ?

data format

{"9356597":{"product_id":9356597,"cat_id":1,"buyer":0,"vendor":2,"price":6},"9356598":{"product_id":9356598,"cat_id":1,"buyer":0,"vendor":2,"price":6}}


Please sign in or create an account to participate in this conversation.