php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76053 Memory leaks when executing prepared statements
Submitted: 2018-03-05 16:50 UTC Modified: 2018-03-06 19:03 UTC
Votes:4
Avg. Score:4.8 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:4 (100.0%)
Same OS:3 (75.0%)
From: hello at spaceemotion dot net Assigned:
Status: Closed Package: PDO MySQL
PHP Version: 7.2.2 OS: Ubuntu
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: hello at spaceemotion dot net
New email:
PHP Version: OS:

 

 [2018-03-05 16:50 UTC] hello at spaceemotion dot net
Description:
------------
I've just come across an out of memory issue in a larger CLI-command that does lots calculations across multiple tables. The command ran fine on 7.1.x but errors on 7.2.2. I've nailed it down to the PDOStatement class (using Blackfire.io) sometimes creating 26 kb garbage _per call_.

The attached test script should not create any garbage whatsoever, and even the gc_collect_cycles call does not reduce the memory footprint. Everything works when running it under 7.1. Opcache is disabled (for CLI).

Test script:
---------------
<?php

$dsn = 'mysql:dbname=homestead;host=127.0.0.1';
$user = 'homestead';
$password = 'secret';

$pdo = new PDO($dsn, $user, $password);

for($i = 0; $i < 1000000; $i++) {
    echo memory_get_usage() . "\n";
    $statement = $pdo->prepare('SELECT * FROM demo');
    $statement->execute();

    gc_collect_cycles(); // does not help as well
}


Expected result:
----------------
362504
107678504
107678504
107678504
107678504
107678504
107678504
107678504

Actual result:
--------------
574888
100246184
100246312
100246440
100246568
100246696
100246824
100246952

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-06 19:03 UTC] hello at spaceemotion dot net
-Status: Open +Status: Closed -PHP Version: 7.2Git-2018-03-05 (snap) +PHP Version: 7.2.2
 [2018-03-06 19:03 UTC] hello at spaceemotion dot net
This was actually a problem with the Laravel Homestead Box where Zend Z-Ray was also enabled for the CLI. Fixed by https://github.com/laravel/settler/pull/145
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon May 27 07:01:26 2019 UTC