Skip to content

Instantly share code, notes, and snippets.

@phpdave
Last active September 6, 2017 13:18
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 phpdave/b49b64b44197c8a3400b6d82f7f39d26 to your computer and use it in GitHub Desktop.
Save phpdave/b49b64b44197c8a3400b6d82f7f39d26 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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