Issues

ZF-2375: Zend_Db_Statement_Mysqli::_execute() causes too much memory to be allocated.

Issue Type: Bug Created: 2008-01-02T16:27:53.000+0000 Last Updated: 2008-09-02T10:38:52.000+0000 Status: Resolved Fix version(s): - 1.6.0 (02/Sep/08)

Reporter: Chris Abernethy (brownoxford) Assignee: Luiz Fernando Furtado (kgbfernando) Tags: - Zend_Db

Related issues: Attachments:

Description

Zend_Db_Statement_Mysqli::_execute() calls mysqli_stmt_bind_result() *before* calling mysqli_stmt_execute(), and it does not call mysqli_stmt_store_result() or mysqli_stmt_free_result().

See these two links for reference: * http://us.php.net/manual/en/… * http://bugs.php.net/bug.php?id=32013

Modify the following test case to set the library path and to use the correct database connection parameters.

<pre class="highlight">
<?php

set_include_path(implode(PATH_SEPARATOR, array(
    '/opt/software/ZendFramework/1.0.3/library'
,   get_include_path()
)));

require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();

try {
    $dbh = Zend_Db::factory('mysqli', array(
        'host'     => '127.0.0.1',
        'username' => 'phpunit',
        'password' => 'phpunit',
        'dbname'   => 'test'
    )); 
    $dbh->getConnection();
} catch (Zend_Exception $e) {
    echo $e->getMessage();
    exit;
}

$dbh->query("DROP TABLE IF EXISTS `zend_testcase`");
$dbh->query("
    CREATE TABLE `zend_testcase` (
        `column_a` tinytext
    ,   `column_b` text
    ,   `column_c` mediumtext
    )
");
$dbh->query("INSERT INTO `zend_testcase` VALUES('a', 'b', 'c')");

$mem = memory_get_usage();
$dbh->query("SELECT `column_a` FROM `zend_testcase`");
echo "Memory Used(TINYTEXT  ): " . (memory_get_usage() - $mem) . "\n";

$mem = memory_get_usage();
$dbh->query("SELECT `column_b` FROM `zend_testcase`");
echo "Memory Used(TEXT      ): " . (memory_get_usage() - $mem) . "\n";

$mem = memory_get_usage();
$dbh->query("SELECT `column_c` FROM `zend_testcase`");
echo "Memory Used(MEDIUMTEXT): " . (memory_get_usage() - $mem) . "\n";

$dbh->query('DROP TABLE IF EXISTS `zend_testcase`');

?>

The output shows that the memory used corresponds roughly to the maximum size of the data-type being selected, which is what can be expected when not using mysqli_stmt_store_result() based on the bug report linked above.

<pre class="highlight">
Memory Used(TINYTEXT  ): 1516
Memory Used(TEXT      ): 65324
Memory Used(MEDIUMTEXT): 16711680

If the sequence of events in Zend_Db_Statement_Mysqli::_execute is updated, and a call to mysqli_stmt_store_result() is added, the memory usage drops significantly:

<pre class="highlight">
Memory Used(TINYTEXT  ): 1296
Memory Used(TEXT      ): 20
Memory Used(MEDIUMTEXT): 0

If this approach is used, calls to mysqli_stmt_free_result will also have to be added in the appropriate places.

Comments

Posted by Wil Sinclair (wil) on 2008-03-25T20:43:57.000+0000

Please categorize/fix as needed.

Posted by Luiz Fernando Furtado (kgbfernando) on 2008-04-04T14:58:17.000+0000

Changed the order of code in _execute method and added a call to mysqli_store_result. Changed to _closeCursor added a call to mysqli_free_result.

Fixed 1.5 branch at 9146, and trunk at 9138 and 9139.

Posted by Wil Sinclair (wil) on 2008-09-02T10:38:52.000+0000

Updating for the 1.6.0 release.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts