Created
May 22, 2012 19:37
-
-
Save fprochazka/2771142 to your computer and use it in GitHub Desktop.
Test case for PDO memory leak - MySQL driver only
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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