duanjuebiao6730 2014-09-09 14:38
浏览 53
已采纳

应用程序在提取数据时挂起

I have noticed several times. we have a front end application created in php. it can extract data from MySQL database into excel file. when I extract data if data is less (about 1000 rows) it creates an excel file normally size of 1-2 MB. but application hangs or gives connection time out whenever I extract more data (about 100000 rows). do I have to change some parameters in php.ini file? I think this might be an error of memory allocation. but not sure which parameter to change.

  • 写回答

1条回答 默认 最新

  • douyou7878 2014-09-09 14:42
    关注

    Look into PHP's output buffer. You can send data as it becomes available.

    Look at this for reference: http://php.net/manual/en/function.ob-start.php and this as an example http://www.andrew-kirkpatrick.com/2013/08/output-csv-straight-to-browser-using-php/

    Edit: Just a thought, you can monitor the status of your database (in case it's the issue here). In your MySQL client you can execute this command show processlist; repeatedly to see what state the DB is in. If your script times out after the query has successfully completed, you can rule out a long running query.

    Also if you're concerned about memory, you shouldn't put all your data in one variable. Really what you should be doing is writing out as you get information in. Seeing your code would help, but basically something along the lines of:

    while ($row = mysql_fetch_assoc($result)) {
        echo "<td>{$result['firstname']}</td>";
    }
    

    is much better than:

    $rows = array();
    while ($row = mysql_fetch_assoc($result)) {
        $rows[] = $row;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥15 流式socket文件传输答疑
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接