dqd54099 2018-09-15 20:14
浏览 129
已采纳

多个SELECT查询中的PDO / mysqli内存泄漏

I have a memory leak when executing many (20,000) simple SELECT operations using PDO or mysqli.

// test2.php
$i = 0;
while (true) {

    $pdo->query("SELECT 1 as m");
    file_put_contents(__FILE__ . '.log', 'Memory: ' . memory_get_usage_in_mb() . PHP_EOL, FILE_APPEND);
    // In test2.php.log
    // ([line]: [message]):
    // 1:     Memory: 0.39
    // 5000:  Memory: 0.44
    // 10000: Memory: 0.51
    // 20000: Memory: 0.63

    if ($i === 20000) {
        break;
    }
    $i++;
}

Plese see full test code at https://gist.github.com/NewEXE/ca4f5ddbeb7ff863b8c775c238698c57

I also tried PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false with $pdo::closeCursor call after each query and this code on mysqli case:

$result = $mysqli->query("SELECT 1 as m", MYSQLI_USE_RESULT); // and MYSQLI_STORE_RESULT too...

// with and without this lines:
$result->free_result();
$result = null;
unset($result);
  • Server: nginx/1.13.6
  • PHP: 7.2.7-1+ubuntu16.04.1+deb.sury.org+1
  • MySQL: 5.7.21-0ubuntu0.16.04.1
  • pdo_mysql: Client API version - mysqlnd 5.0.12-dev - 20150407
  • mysqli: Client API library version - mysqlnd 5.0.12-dev - 20150407

Sorry for my english and thank you in advance!

  • 写回答

2条回答 默认 最新

  • douhuan9289 2018-09-18 19:27
    关注

    I disabled xDebug and the problem is solved!

    Tnanks to this answer: https://stackoverflow.com/a/43359644/8927920

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

报告相同问题?

悬赏问题

  • ¥15 求指导储层饱和度及含水率测井解释
  • ¥200 建三维地震工区写入sgy到指定目录
  • ¥30 靶向捕获测序探针设计自学
  • ¥15 写代码写代码单片机代码写代码写数字按键代码
  • ¥15 django按照距离进行排序
  • ¥15 (标签-微信|关键词-微信公众号)
  • ¥15 matlab中mjs用不了
  • ¥15 Ios抖音直播的时候如何添加自定义图片在直播间!
  • ¥60 riscv-pulpino总线上挂载axi从机
  • ¥15 ssh登录页面的问题