我试图通过我的symfony项目中的ajax获取一些数据库数据。我抓住了我们数据库中的所有估算值,超过了60k。当我尝试json_encode结果时,我得到一个内存不足的错误。我知道它与大小有关,因为我可以json_encode一个结果,它返回正常。
$results = new \stdClass;
$results->jobs = $epms->getEstimates();
// JSON encode results to send to the view. The view just echos them out for jQuery to process.
$json_encoded = json_encode($results->jobs[1]); //Works
$json_encoded = json_encode($results->jobs); //Doesn't work
$headers = array(
'Content-Type' => 'application/json'
);
$response = new Response($json_encoded, 200, $headers);
return $response;
我是一个PHP菜鸟,但我的想法是分割结果并编码较小的部分,然后我可以在返回到我的ajax调用之前将它们连接在一起。对此最好的方法是什么?我不想增加我的php内存限制。
答案 0 :(得分:1)
您需要动态增加内存限制: -
ini_set('memory_limit','16M');// change 16M to your desired number
注意: -
上面的代码会将PHP可用的最大内存量增加到16 MB,并且此设置仅针对正在运行的脚本进行调整。