ID: 25962
User updated by: liu-shan at mediaring dot com
Reported By: liu-shan at mediaring dot com
-Status: Feedback
+Status: Open
Bug Type: Informix related
Operating System: sun
PHP Version: 4.3.2
New Comment:
Hi, below is a sample, just for your reference.
I created a class call c_informix to fulfill connect to informix db and
insert data to it. I write a php program to call this class to insert
500,000 records into to test table, the program would auto died during
process. If you use some tools such as "top" to monitor this php
program, your could see the value of memory increased very fast. As
normal, after insert one record, the memory should release, but real
thing is the memory not release properly, once you continuous to insert
a large records, the momory goes to large value, system will auto kill
this process.
// c_informix.php ===
close();
break;
}
}
exit;
function TestInsert($ifmx, $acc, $dbg)
{
$result = true;
$Liststmt = "insert into ls_test (lt_acct, lt_requester,
lt_reasoncode)";
$Liststmt .= " values ('${acc}', 'm', 7000);";
$ret = $ifmx->insert($Liststmt);
if (!$ret)
{
$fstr = "Error - " . $ifmx->errno() . ", " . $ifmx->error() .
" - " . $Liststmt . " - test_db.php";
WriteToLog($dbg, "daemon", "daemon", $fstr);
$result = false;
echo("error = " . $fstr . "\n\n");
}
return $result;
}
?>
// c_informix.php ===
class c_informix
{
// public: current error number and error text
var $ErrNo= "";
var $Error= "";
// private: connection parameters
var $Server= "";
var $Password= "";
var $User= "";
var $Conn= "";
function c_informix ($dbserver = "", $dbuser = "" , $dbpassword =
"")
{
$this->Server= $dbserver;
$this->User= $dbuser;
$this->Password= $dbpassword;
if (!empty($this->Server) && !empty($this->User) &&
!empty($this->Password))
{
$this->connect();
}
}
function connect()
{
$numtries = 50;
$this->Conn = @ifx_connect($this->Server, $this->User,
$this->Password);
while (!$this->Conn && $numtries)
{
usleep(20);
$this->Conn = @ifx_connect($this->Server, $this->User,
$this->Password);
$numtries--;
}
if (!$this->Conn)
{
$this->set_error();
return false;
}
return true;
}
function insert ($sql="")
{
$results = false;
if (empty($sql))
{
$this->set_error("DB0002", "Empty command(s)");
}
else if (!eregi("^insert",$sql))
{
$this->set_error("DB0010", "Syntax
Error--".$sql."--");
}
else if (empty($this->Conn))
{
$this->set_error("DB0001", "Connection not
established");
}
else
{
$results = @ifx_query($sql,$this->Conn);
if ($results)
{
$results = @ifx_affected_rows($results);
}
else
{
$results = false;
$this->set_error();
}
}
return $results;
}
function set_error($errcode = "", $error = "")
{
if(!empty($errcode) && !empty($error))
{
$this->Error = $error;
$this->ErrNo = $errcode;
}
else
{
$this->Error = @ifx_errormsg();
$this->ErrNo = strtok(strstr(ifx_error(), "-"),
"]");
}
return true;
}
// public: returns the last error number
function errno()
{
return $this->ErrNo;
}
// public: returns the last error