I have a table with ~70k records and is ~12 MiB(MB) in size.
require_once('connection.php');
$sql = "SELECT * FROM BlahBlah";
$result = $con->query($sql);
$data = array();
while($row = $result->fetch_assoc()) {
$data[] = $row;
}
echo json_encode($data);
When I do a while fetch_assoc() loop in PHP to store the result and echo back all the rows in the table in Json format to javascript, I get Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes)
.
I understand that more than 12 MiB of memory is definitely required, but allocating 10 times as much memory as needed throws me off. I have one other query before this and it only grabs a 151 KB table.
EDIT: I've read the blog post below to understand why PHP needs so much overhead.
One solution is to set the memory limit to unlimited, but that seems like a horrible approach as my database grows at ~10k records per day. Is there any other way to output all the rows of a table from MySQL in Json format to the client? I'm generating google map markers on the client side from the rows obtained