douduidui1046 2015-09-11 16:13
浏览 104

PHP oci_fetch_array导致内存不足错误

Im am running a query and retrieving with OCI_FETCH_ARRAY and I am getting a fatal error, out of memory after I hit a certain volume of records. The result array is 100k rows and about 60 columns.
I have my memory_limit in php.ini set to 2 gigs.

memory_limit = 2056M

It seems to happen when I have more than one person running the script at the same time (or same person running twice as it is set up to run in the background). It only takes 2 concurrent jobs of 100k records to cause the error. Everything I've found on OCI_FETCH_ARRAY states that it isn't caching the whole result set in to memory but it looks like it IS.

This is my code (Very straight forward)

while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
    array_push($resultfile,$row);
    $tablerow=$tablerow +1;
    unset($row);
}

The error happens on the OCI_FETCH_ARRAY statement after it hits a certain number of loops.

The output file is only 94m (avg) so doesn't seem like I should be anywhere memory limit.

  • 写回答

1条回答 默认 最新

  • duanpi2033 2019-05-02 05:05
    关注

    below code is causing high memory usage :

    array_push($resultfile,$row);
    

    oci_fetch_array is unbuffered meaning it will fetch rows one by one until no rows exists. I would suggest not to push row into another array. instead write your logic inside while loop itself.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度