dpwtr666638 2015-05-27 16:44
浏览 290
已采纳

JSON响应对PHP来说太大了?

Working with a database I've created, I can run search queries that output data in JSON, then send them back to my webpage. Pretty standard.

$searchQuery  = "SELECT * FROM alldata where $searchBy like '%$searchValue%'" ;
$searchResult = mysqli_query($con, $searchQuery);

while ($row = mysqli_fetch_row($searchResult)) {

$item = array();
    $item["dateReceived"] = convertDate($row[1]);    
    $item["quoteCost"] = $row[15];
    $item["quoteNumber"] = $row[16];
    $item["quoteExpDate"] = convertDate($row[17]);    
    $item["comments"] = $row[21];    

    $output[] = $item; 
    }

$out = array('aaData' => $output);    
echo json_encode($out);

When my query is too general, something fails, and I'm not sure where it is.

The response I get from the server is:

Fatal error :  Allowed memory size of 134217728 bytes exhausted (tried to allocate 14680165 bytes) in C:\xampp\htdocs\....php</b> on line <b>74</b><br />

My memory limit is set in php.ini as:

memory_limit=128M

If I go into mySQL and write SELECT * FROMalldataWHERE name like "%a%"; I get about 35,000 rows, each with about 20 columns, but it only takes a split second.

The amount that I can query against the table is prohibitively small - what can I do to fix this so my users can run more generic queries?

  • 写回答

4条回答 默认 最新

  • douwu7168 2015-05-27 16:59
    关注

    There is no way a user is going to want to see all 35,000 rows at once in one page.

    This would:

    (1) Increase the execution time of the script.

    (2) Probably crash the browser trying to display so much of data.

    For effective execution of the script use pagination and/or put limits on your queries.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题