Bug #70901 [NEW]: PDO memory leak for MySQL
From: nhojohl at gmail dot com
Operating system: Ubuntu 10.04
PHP version: 5.6.15
Package: PDO MySQL
Bug Type: Bug
Bug description:PDO memory leak for MySQL
Description:
------------
We have a few extremely long running PHP command line scripts that
experience continual memory usage growth until eventually running out
of memory altogether. It took awhile to narrow down the cause, but I
believe there's a memory leak in the PDO connection creation process for
the MySQL driver.
If you create a connection, any attempt to destroy it will still leave
you with a memory usage growth of ~900 bytes.
php -m
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dba
dom
ereg
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
imagick
json
libxml
mbstring
memcached
mhash
mysql
mysqli
mysqlnd
newrelic
openssl
pcntl
pcre
PDO
pdo_mysql
Phar
posix
pthreads
readline
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xdebug
xml
xmlreader
xmlwriter
Zend OPcache
zip
zlib
[Zend Modules]
Xdebug
Zend OPcache
Test script:
---------------
<?php
$attributes = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_EMULATE_PREPARES => false,
PDO::ATTR_TIMEOUT => 30,
PDO::MYSQL_ATTR_SSL_CA =>
'/etc/pki/tls/certs/mysql-ssl-ca-cert.pem',
PDO::MYSQL_ATTR_COMPRESS => true
);
for ($i = 0; $i < 100000; ++$i) {
$db = null;
try {
$db = new
PDO('mysql:host=localhost;port=3306;dbname=test;charset=utf8', 'test',
'abc123', $attributes);
} catch (PDOException $e) {
echo $e->getMessage();
}
$db = null;
echo memory_get_usage().'/'.memory_get_usage(true)."\n";
}
Expected result:
----------------
Semi-consistent memory usage
Actual result:
--------------
Memory usage continually grows
229016/262144
229912/262144
230808/262144
231704/262144
232664/262144
233560/262144
234456/262144
235352/262144
236248/262144
237144/262144
238064/262144
238960/262144
239984/262144
240880/262144
241800/262144
242696/262144
243592/262144
244512/262144
245408/262144
246304/262144
247224/262144
248120/262144
249016/262144
249920/262144
250816/262144
251712/524288
252632/524288
253528/524288
254680/524288
255576/524288
256472/524288
257368/524288
258288/524288
259184/524288
260080/524288
....
--
Edit bug report at https://bugs.php.net/bug.php?id=70901&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70901&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70901&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70901&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70901&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70901&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70901&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70901&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70901&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70901&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70901&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70901&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70901&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70901&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70901&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70901&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70901&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70901&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70901&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70901&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70901&r=mysqlcfg
Thread (5 messages)
- nhojohl at gmail dot com