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 ===
<?
//test.php

define("CONF_DIR", "/test/cbConf");
define("LOG_DIR", "/test/cbLogs/");
        
include_once(CONF_DIR.'common.php');
include_once(CONF_DIR.'c_informix.php');
   
set_time_limit(0);
   
        
$t_date = date("Ymd");
$debug_file = LOG_DIR . "ls_debug_" . $t_date . ".log"; 
        
        
$ifmx = new c_informix(DB_NAME, DB_USERNAME, DB_USERPASSWORD);
 
for ($i=1; $i<1000000; $i++)
{
   if (!TestInsert($ifmx, $i, $debug_file))
   {
        $ifmx->close();
        break;
   }
}
        
exit;
        
        
        
function TestInsert($ifmx, $acc, $dbg)
{
   $result = true;
        
   $Liststmt = "insert into ls_test (lt_acct, lt_requester,
lt_reasoncode)";
   $Liststmt .= " values ('${acc}', 'mmmmm', 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 message
        function error()
        {
                return $this->Error;
        }

        function close()
        {
                @ifx_close($this->Conn);
        }
}


Previous Comments:
------------------------------------------------------------------------

[2003-10-23 22:48:26] [EMAIL PROTECTED]

Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.




------------------------------------------------------------------------

[2003-10-23 04:40:54] liu-shan at mediaring dot com

Description:
------------
I'm PHP programer, I write web application using PHP connect to
informix database, informix CSDK version 2.7.1, no matter I SELECT,
INSERT OR UPDATE data to database, once program exit, but memory still
that, cannot release. it cause os memory leak, I have to reboot server
frequently.
How can I resolve this problem



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=25962&edit=1

Reply via email to