Skip to content

Instantly share code, notes, and snippets.

@phpdave

phpdave/Proof.php

Last active Sep 6, 2017
Embed
What would you like to do?
Apparent Memory leak in External Stored Procedure with INOUT param w/ PHP's IBM DB2 extension 1.9.9 when binding the parameter in PHP7. When the bindparam on the out parameter is done outside of the loop memory doesn't increase.
CREATE OR REPLACE PROCEDURE MYLIB.TESTSP (
IN "ID" DECIMAL(7, 0) ,
INOUT CUSTOMERNAME CHAR(40) )
LANGUAGE RPGLE
SPECIFIC MYLIB.TESTSP
NOT DETERMINISTIC
NO SQL
CALLED ON NULL INPUT
EXTERNAL NAME 'MYLIB/MYTESTRPG'
PARAMETER STYLE GENERAL ;
<?php
$db2Connection = db2_connect('MYDB', 'MYUSER', 'MYPASS',array('i5_lib' => 'MYLIB'));
$sql = "CALL MYLIB.TESTSP(?,?)";
$stmt = db2_prepare($db2Connection, $sql);
for ($i = 0; $i <= 20; $i++)
{
if ($stmt)
{
$id = 20;
$name = "";
db2_bind_param($stmt, 1, "id", DB2_PARAM_IN);
db2_bind_param($stmt, 2, "name", DB2_PARAM_OUT);
if (db2_execute($stmt))
{
var_dump($name);
echo "<br>";
echo "Memory usage: ";
var_dump(memory_get_usage());//Memory usage increases 64 Bytes per call, in old DB2 Memory stays constant.
echo "<br>";
}
}
else
{
echo "<b>Last SQL Statement Error Message:</b> ".db2_stmt_errormsg()."<br>";
}
if($db2Connection===FALSE)
{
echo "<b>Last Connection Error Message:</b> ".db2_conn_errormsg()."<br>";
}
}
exit();
@phpdave

This comment has been minimized.

Copy link
Owner Author

@phpdave phpdave commented Sep 1, 2017

if php variable $name is outside of the loop
$name = "";
memory doesn't increase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment