php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39058 Memory Leak
Submitted: 2006-10-06 08:54 UTC Modified: 2007-05-13 01:00 UTC
Votes:30
Avg. Score:4.7 ± 0.7
Reproduced:27 of 27 (100.0%)
Same Version:16 (59.3%)
Same OS:3 (11.1%)
From: mpcribeiro at yahoo dot com Assigned:
Status: No Feedback Package: Sybase-ct (ctlib) related
PHP Version: 5.1.6 OS: Solaris 10
Private report: No CVE-ID: None
 [2006-10-06 08:54 UTC] mpcribeiro at yahoo dot com
Description:
------------
PHP 5.1.6 compiled and installed without issues.

However when procedures call sybase functions and after few minutes. PHP complain with not enough memory. 

PHP seem unable to read all the script, also unable to address the variables properly.

At beggining gave "fatal errors" due to lack of memory even with 200Mb has memory limit (raised from its default value).

After recompiling php 5.1.6 for 2nd time, I'm now getting the following errors, and lack of memory (200mb limit) message is now rare to appear.

Warning: Unknown list entry type in request shutdown (0) in lib/lib_syb_sessions.php on line 61

Warning: Unknown list entry type in request shutdown (0) in /lib/lib_syb_sessions.php on line 42


PHP 5.1.6 was compiled with the following parameters:

PHPHOME=/opt/php
APACHEHOME=/opt/apache
cat /dev/null > conf.log
export PATH=$PATH:/var/MailRoot/bin
./configure     --prefix=$PHPHOME \
                --bindir=$PHPHOME/bin \
                --libdir=$PHPHOME/lib \
                --with-config-file-path=$PHPHOME/conf \
                --with-apache2=$APACHEHOME/ \
                --with-apxs2=$APACHEHOME/bin/apxs \
                --with-sfw=/usr/sfw \
                --with-jpeg \
                --with-jpeg-dir=/usr/local \
                --with-png \
                --with-png-dir=/usr/local \
                --with-ftp \
                --with-zlib-dir=/usr/local \
                --enable-magic-quotes \
                --enable-safe-mode \
                --enable-sockets \
                --enable-track-vars \
                --enable-trans-sid \
                --enable-memory-limit \
                --enable-calendar \
                --with-pgsql=/opt/pgsql \
                --with-mysql-dir=/opt/mysql \
                --with-sybase-ct=$SYBASE/$SYBASE_OCS \
                --enable-static=sybase-ct \
                --enable-mbstring

I have reviewed the procedure few times and I can't find any glitch that could cause such behaviour.

I'm now compiling the latest 5.2* from dev's cvs to see if this issue is solved. Cheers

Reproduce code:
---------------
function syb_list_processes($DBase,$DBusr,$DBpwd,$SID,$SN,$SYBSN,$ORDER) {
        putenv("SYBASE=/opt/sybase");
        putenv("SYBPLATFORM=solaris");
        putenv("LC_ALL=default");
        putenv("DSQUERY=SYBASE");
        $lg=read_session_id($SID,'login');
        if(!$ORDER) {
                $ORDER='suid';
        }
        $SYBusr=syb_get_sadetails($DBase,$DBusr,$DBpwd,$SN,$SYBSN,'sausr');
        $SYBpwd=syb_get_sadetails($DBase,$DBusr,$DBpwd,$SN,$SYBSN,'sapwd');
        $connect=@sybase_connect("$SYBSN","$SYBusr","$SYBpwd");
        if($ORDER=="") {
                $ORDER='suid';
        }
        switch ($ORDER) {
                case 'cpu':     $SORTORDER="DESC";
                                break;
                case 'physical_io':     $SORTORDER="DESC";
                                        break;
                case 'memusage':        $SORTORDER="DESC";
                                        break;
                case 'cmd':     $SORTORDER="DESC";
                                        break;
                default:        $SORTORDER="";
                                break;
        }
         $string="SELECT * FROM sysprocesses WHERE program_name NOT LIKE 'PHP %'
ORDER BY $ORDER $SORTORDER";
        $sybres=sybase_query($string);
        if($sybres) {
                $flag=0;
                $NROWS=@sybase_num_rows($sybres);
                printf("NROWS=%s",$NROWS);
                printf("<TABLE width=760>");
                printf("<TR><TD><B>No. Procs</B></TD><TD><FONT color=blue>%s</FO
NT></TD></TR>",$NROWS);
                printf("<TR BGCOLOR='darkgrey'>
                        <TD><A HREF='syb_procs_lst.php?sid=%s&server=%s&sybserve
r=%s&order=spid'><B>SPID</B></A></TD>",$SID,$SN,$SYBSN);
                printf("<TD><A HREF='syb_procs_lst.php?sid=%s&server=%s&sybserve
r=%s&order=status'><B>Status</B></A></TD>",$SID,$SN,$SYBSN);
                printf("<TD><A HREF='syb_procs_lst.php?sid=%s&server=%s&sybserve
r=%s&order=suid'><B>User</B></A></TD>",$SID,$SN,$SYBSN);
                printf("<TD><A HREF='syb_procs_lst.php?sid=%s&server=%s&sybserve
r=%s&order=dbid'><B>Database</B></A></TD>",$SID,$SN,$SYBSN);
                printf("<TD><A HREF='syb_procs_lst.php?sid=%s&server=%s&sybserve
r=%s&order=cmd'><B>CMD</B></A></TD>",$SID,$SN,$SYBSN);
                printf("<TD><A HREF='syb_procs_lst.php?sid=%s&server=%s&sybserve
r=%s&order=cpu'><B>CPU</B></A></TD>",$SID,$SN,$SYBSN);
                printf("<TD><A HREF='syb_procs_lst.php?sid=%s&server=%s&sybserve
r=%s&order=physical_io'><B>I/O</B></A></TD>",$SID,$SN,$SYBSN);
                printf("<TD><A HREF='syb_procs_lst.php?sid=%s&server=%s&sybserve
r=%s&order=memusage'><B>RAM</B></A></TD>",$SID,$SN,$SYBSN);
                printf("<TD><A HREF='syb_procs_lst.php?sid=%s&server=%s&sybserve
r=%s&order=clienthostname'><B>Hostname</B></A></TD>",$SID,$SN,$SYBSN);
                printf("<TD><A HREF='syb_procs_lst.php?sid=%s&server=%s&sybserve
r=%s&order=program_name'><B>Program</B></A></TD>",$SID,$SN,$SYBSN);
                printf("<TD><A HREF='syb_procs_lst.php?sid=%s&server=%s&sybserve
r=%s&order=ipaddr'><B>IP</B></A></TD>",$SID,$SN,$SYBSN);
                printf("<TD></TD>");
                printf("</TR>");
                for ($i=0; $i < $NROWS; $i++) {
                        $SYBSPID=@sybase_result($sybres,$i,0);
                        $SYBSTATUS=@sybase_result($sybres,$i,3);
                        $SYBSUID=@sybase_result($sybres,$i,5);
                        $SYBHOST=@sybase_result($sybres,$i,29);
                        $SYBPRG=@sybase_result($sybres,$i,6);
                        $SYBCMD=@sybase_result($sybres,$i,8);
                        $SYBDB=@sybase_result($sybres,$i,13);
                        $SYBIP=@sybase_result($sybres,$i,34);
                        $SYBCPU=@sybase_result($sybres,$i,9);
                        $SYBIO=@sybase_result($sybres,$i,10);
                        $SYBMEM=@sybase_result($sybres,$i,11);
                        switch (trim($SYBSTATUS,' ')) {
                                case "running":         $COLOR='green';
                                                        break;
                                default:                $COLOR='black';
                                                        break;
                        }
                         if($flag==0) {
                                printf("<TR>
                                        <TD><A HREF='processes3.php?SN=%s&SPID=%
s&lg=%s&pw=%s'><FONT SIZE=0>%s</FONT></A></TD>",$SN,$SYBSPID,$lg,$pw,$SYBSPID);
                                printf("<TD><FONT SIZE=0 COLOR=%s>%s</FONT></TD>
",$COLOR,$SYBSTATUS);
                                printf("<TD><FONT SIZE=0 COLOR=%s>%s</FONT></TD>
",$COLOR,syb_get_login($DBase,$DBusr,$DBpwd,$SN,$SYBSN,$SYBSUID));
                                printf("<TD><FONT SIZE=0 COLOR=%s>%s</FONT></TD>
",$COLOR,syb_get_database($DBase,$DBusr,$DBpwd,$SN,$SYBSN,$SYBDB));
                                printf("<TD><FONT SIZE=0 COLOR=%s>%s</FONT></TD>
",$COLOR,$SYBCMD);
                                printf("<TD><FONT SIZE=0 COLOR=%s>%s</FONT></TD>
",$COLOR,$SYBCPU);
                                printf("<TD><FONT SIZE=0 COLOR=%s>%s</FONT></TD>
",$COLOR,$SYBIO);
                                printf("<TD><FONT SIZE=0 COLOR=%s>%s</FONT></TD>
",$COLOR,$SYBMEM);
                                printf("<TD><FONT SIZE=0 COLOR=%s>%s</FONT></TD>
",$COLOR,$SYBHOST);
                                printf("<TD><FONT SIZE=0 COLOR=%s>%s</FONT></TD>
",$COLOR,$SYBPRG);
                                printf("<TD><FONT SIZE=0 COLOR=%s>%s</FONT></TD>
",$COLOR,$SYBIP);
                                if($lg<>"demo") {
                                        printf(" <TD><A HREF='killprocess.php?SN
=%s&SPID=%s&lg=%s&pw=%s'><IMG SRC=img/disable.gif width=10 height=10 border=0 ti
tle='Kill Process'></A></TD>",$SN,$SYBSPID,$lg,$pw);
                                } else {
                                        printf(" <TD><IMG SRC=img/disable.gif wi
dth=10 height=10 border=0 title='Kill Process'></TD>");
                                }
                                printf("</TR>");
                                $flag++;
                        } else {
                                printf("<TR BGCOLOR='lightgrey'>
                                        <TD><A HREF='processes3.php?SN=%s&SPID=%
s&lg=%s&pw=%s'><FONT SIZE=0>%s</FONT></A></TD>",$SN,$SYBSPID,$lg,$pw,$SYBSPID);
                                printf("<TD><FONT SIZE=0 COLOR=%s>%s</FONT></TD>
                                        <TD><FONT SIZE=0 COLOR=%s>%s</FONT></TD>
                                        <TD><FONT SIZE=0 COLOR=%s>%s</FONT></TD>
                                        <TD><FONT SIZE=0 COLOR=%s>%s</FONT></TD>
                                        <TD><FONT SIZE=0 COLOR=%s>%s</FONT></TD>
                                        <TD><FONT SIZE=0 COLOR=%s>%s</FONT></TD>
                                        <TD><FONT SIZE=0 COLOR=%s>%s</FONT></TD>
                                        <TD><FONT SIZE=0 COLOR=%s>%s</FONT></TD>
                                        <TD><FONT SIZE=0 COLOR=%s>%s</FONT></TD>
                                        <TD><FONT SIZE=0 COLOR=%s>%s</FONT></TD>
                                        ",
                                        $COLOR,$SYBSTATUS,
                                        $COLOR,syb_get_login($DBase,$DBusr,$DBpw
d,$SN,$SYBSN,$SYBSUID),
                                        $COLOR,syb_get_database($DBase,$DBusr,$D
Bpwd,$SN,$SYBSN,$SYBDB),
                                        $COLOR,$SYBCMD,
                                        $COLOR,$SYBCPU,
                                        $COLOR,$SYBIO,
                                        $COLOR,$SYBMEM,
                                        $COLOR,$SYBHOST,
                                        $COLOR,$SYBPRG,
                                        $COLOR,$SYBIP);
                                if($lg<>"demo") {
                                        printf(" <TD><A HREF='killprocess.php?SN
=%s&SPID=%s&lg=%s&pw=%s'><IMG SRC=img/disable.gif width=10 height=10 border=0 ti
tle='Kill Process'></A></TD>",$SN,$SYBSPID,$lg,$pw);
                                } else {
                                        printf(" <TD><IMG SRC=img/disable.gif wi
dth=10 height=10 border=0 title='Kill Process'></TD>");
                                }
                                printf("</TR>");
                                $flag=0;
                        }
                }
        }
        printf("</TABLE>");
        @sybase_close($connect);
}

Expected result:
----------------
No fatal errors with lack of memory (im now using 200Mb) where in previous versions I used the default value.

The variables showing the correct content (not empty content or values mixed between vars).


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-06 08:59 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip


 [2006-10-06 09:17 UTC] mpcribeiro at yahoo dot com
Fatal error: Allowed memory size of 209715200 bytes exhausted (tried to allocate 1835103092 bytes) in /data/www/ribeiros/syb/lib/lib_syb_sessions.php on line 66

Still with 5.1.6 and memory limit of 200Mb


I'm currently compiling the latest PHP 5.2* available from devs cvs... lets see. Cheers
 [2007-05-13 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2008-03-03 07:33 UTC] kristjan at laborint dot com
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 2560000 bytes)

PHP:
PHP Version 5.2.5

System:
Linux z37 2.6.9-67.0.4.ELsmp #1 SMP Sun Feb 3 07:06:14 EST 2008 x86_64

Server API:
CGI/FastCGI

Sybase:
Client API Version $Id: dblib.c,v 1.244.2.1 2006/01/31 08:45:20 freddy77 Exp $
 [2008-06-13 09:44 UTC] daniel dot buschke at nextiraone dot de
# php -v
PHP 5.2.6RC4-pl0-gentoo (cli) (built: Jun 13 2008 11:18:19)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies

Still the same problem. Please reopen 'cause bug seems not fixed.

Let me know how I can provide further informations - if needed.
 [2008-06-13 09:46 UTC] daniel dot buschke at nextiraone dot de
Noticed that mpcribeiro is using sybase bindings. I use freetds! So it is not a problem of the bindings, is it?
 [2008-06-24 14:55 UTC] jjsainzc at gmail dot com
I'm use freetds and php5.1.6

I have the same problem:

Source (part):

$connect_sybase_id=sybase_connect("Database","login","pass");

if ($connect_sybase_id)
    echo "Conectado\n";
else
    echo "No conectado\n";

if (sybase_select_db("Database"))
    echo "Seleccionada la base\n";
else
    echo "No pude seleccionar la base\n";


$query="SELECT field FROM DBA.tabla WHERE codigo=1";
$result = false;
$result = sybase_query($query);

if ($result) {
    $r=sybase_fetch_row($result);
    echo "Resultado\n";
    print_r($r);
}
else echo "No pude hacer el query\n";
sybase_close($connect_sybase_id);



Result:

Fatal error: Allowed memory size of 209715200 bytes exhausted (tried to allocate 56 bytes) in /home/support/prueba.php on line 30
 [2009-09-23 04:45 UTC] gi_mike2002 at yahoo dot com
No movement on this since 2006?!

tsk, tsk...
 [2013-05-10 16:07 UTC] dbabits at gmail dot com
getting the same problem.

-PHP 5.4.3 (cgi-fcgi) (built: May  9 2013 17:03:23)
-built --with-sybase-ct=/path/to/freetds
-code:

$con = sybase_connect('server', 'user', 'pwd');
$q = sybase_query("select col=1", $con);

Output:
<b>Fatal error</b>:  Allowed memory size of 134217728 bytes exhausted (tried to 
allocate 30064771074 bytes)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 01 20:01:29 2024 UTC