Bug #81059 [Opn->Fbk]: Memory leaks PDO MySQL reading blob field

From: Date: Thu, 27 May 2021 08:23:11 +0000
Subject: Bug #81059 [Opn->Fbk]: Memory leaks PDO MySQL reading blob field
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-234039@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81059&edit=1

 ID:                 81059
 Updated by:         nikic@php.net
 Reported by:        andresr dot alz at gmail dot com
 Summary:            Memory leaks PDO MySQL reading blob field
-Status:             Open
+Status:             Feedback
 Type:               Bug
 Package:            PDO MySQL
 Operating System:   Docker FROM php:8.0.6-cli
 PHP Version:        8.0.6
 Block user comment: N
 Private report:     N

 New Comment:

Could you please provide the schema/contents of the test table you're using here? I tried with
some dummy values, but wasn't able to reproduce a leak.

Also, as you don't have a loop inside the code, I'm assuming that the leak you're
seeing occurs across multiple requests? Each request increasing memory usage?


Previous Comments:
------------------------------------------------------------------------
[2021-05-20 14:07:09] andresr dot alz at gmail dot com

Description:
------------
#### Dockerfile
FROM php:8.0.6-cli
RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-enable pdo_mysql
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
ENTRYPOINT ["php", "testing_pdo.php"]
####

This is not happening with php < 7.3


Test script:
---------------
// testing_pdo.php
<?php

ini_set('memory_limit', '-1');

function _get_connection()
{
  print "\nget_connection";
  $opt = array(
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  );

  try {
    $dbconn = new PDO(
      "mysql:host=" . "localhost",
      "user",
      "user_test",
      $opt
    );
    $dbconn->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
    return $dbconn;
  } catch (PDOException $e) {
    print "Error: $e";
    return null;
  }
}

function _big_query($dbconn)
{
  print "\nbig query running ...";

  $CSV_results = "";
  $sql = "SELECT sent_blob from test WHERE id = 1";
  $stm = $dbconn->prepare($sql);
  $stm->execute();

  $stm->bindColumn(1, $CSV_results, PDO::PARAM_LOB);
  $stm->fetch(PDO::FETCH_BOUND);
  $stm->closeCursor();

  return $CSV_results;
}


print "\nStarting ....";
$conn = _get_connection();
if ($conn != null) {
  $result = _big_query($conn);
  print $result;
}

Expected result:
----------------
Memory on docker container keeps almost the same than network IO

Actual result:
--------------
Memory is increasing in a weird way


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=81059&edit=1


Thread (7 messages)

« previous php.bugs (#234039) next »