Skip to content

Instantly share code, notes, and snippets.

@fprochazka
Created May 22, 2012 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fprochazka/2771142 to your computer and use it in GitHub Desktop.
Save fprochazka/2771142 to your computer and use it in GitHub Desktop.
Test case for PDO memory leak - MySQL driver only
$ php ./pdo_row_memory_leak.php
fetched 127 ... 0.23 MB
fetched 127 ... 0.23 MB
fetched 127 ... 0.23 MB
fetched 127 ... 0.23 MB
fetched 127 ... 0.23 MB
fetched 127 ... 0.23 MB
fetched 127 ... 0.23 MB
fetched 127 ... 0.23 MB
fetched 127 ... 0.23 MB
fetched 127 ... 0.23 MB
fetched 127 ... 0.00 MB
fetched 127 ... 0.05 MB
fetched 127 ... 0.10 MB
fetched 127 ... 0.14 MB
fetched 127 ... 0.19 MB
fetched 127 ... 0.24 MB
fetched 127 ... 0.29 MB
fetched 127 ... 0.34 MB
fetched 127 ... 0.38 MB
fetched 127 ... 0.43 MB
fetched 127 ... 0.05 MB
fetched 127 ... 0.05 MB
fetched 127 ... 0.05 MB
fetched 127 ... 0.05 MB
fetched 127 ... 0.05 MB
fetched 127 ... 0.05 MB
fetched 127 ... 0.05 MB
fetched 127 ... 0.05 MB
fetched 127 ... 0.05 MB
fetched 127 ... 0.05 MB
<?php
// require_once __DIR__ . '/Nette/loader.php';
// Nette\Diagnostics\Debugger::enable(FALSE);
// Nette\Diagnostics\Debugger::$strictMode = TRUE;
$db = new PDO('mysql:host=127.0.0.1;dbname=information_schema', 'root', 'heslo');
class DbRowTwo { }
$begin = memory_get_usage();
for ($i=0; $i < 10 ;$i++) {
$stt = $db->prepare("SELECT * FROM COLLATIONS");
$stt->setFetchMode(PDO::FETCH_CLASS, 'DbRowTwo');
$stt->execute();
$rows = $stt->fetchAll();
echo "fetched ", count($rows), " ... ", number_format((memory_get_usage() - $begin) / 1000000, 2, '.', ' '), " MB\n";
}
echo "\n";
class DbRowOne { public function __construct($stt) { } }
$begin = memory_get_usage();
for ($i=0; $i < 10 ;$i++) {
$stt = $db->prepare("SELECT * FROM COLLATIONS");
$stt->setFetchMode(PDO::FETCH_CLASS, 'DbRowOne', array($stt));
$stt->execute();
$rows = $stt->fetchAll();
echo "fetched ", count($rows), " ... ", number_format((memory_get_usage() - $begin) / 1000000, 2, '.', ' '), " MB\n";
}
echo "\n";
class DbRowThree { public function __construct($stt = NULL) { } }
$begin = memory_get_usage();
for ($i=0; $i < 10 ;$i++) {
$stt = $db->prepare("SELECT * FROM COLLATIONS");
$stt->setFetchMode(PDO::FETCH_CLASS, 'DbRowThree');
$stt->execute();
$rows = $stt->fetchAll();
echo "fetched ", count($rows), " ... ", number_format((memory_get_usage() - $begin) / 1000000, 2, '.', ' '), " MB\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment