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 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 统计大规模图中的完全子图问题
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题