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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
38 - 10 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 04:01:28 2024 UTC