locked
memory leak RRS feed

  • Question

  • Yeasterday, we have launched large website based on PHP 5.2.9-1 (nonTS, but tried TS as well), SQL Server Driver for PHP (October 2008 update), IIS7 and SQL Server 2008. Problem is, php_sqlsrv.dll si slowly eating memory. PHP cgi process slowly grows from 20MB to 300MB, consequently crashing the IIS7 / FastCGI process and leading to "500 Internal Server Error".

    There must be still a memory leak.

    We have only these extensions enabled:
    - extension=php_bz2.dll
    - extension=php_gd2.dll
    - extension=php_mbstring.dll
    - extension=php_xmlrpc.dll
    - extension=php_sqlsrv.dll

    By disabling all of them, except php_sqlsrv.dll, and still finding PHP cgi memory consumption to grow, we are sure this driver is memory leaking.

    Is there a dev / beta / alpha release we could test?
    Monday, April 6, 2009 9:35 AM

Answers

  • Hi Radek,

     

    We started to investigate the memory leak that you reported, but we need one additional clarification from you.  I gather from your last post that despite lowering the recycle interval for FastCGI (via a lower value for “instanceMaxRequests”), you notice a continuous increase in the IIS memory consumption (throughout the day). Is my statement correct?

     

    We would have expected that in the event we have a memory leak in the driver, the shorter recycle time would take care of it. Once a FastCGI instance is recycled, all its accumulated memory is flushed.

     

    Thank you,

    Serban


    Serban Iliescu - MSFT
    • Marked as answer by David Sceppa Wednesday, April 15, 2009 9:45 PM
    Wednesday, April 8, 2009 6:07 PM
    Answerer

All replies

  • Radek,

    We'd like to reproduce and investigate the problem you've described.  Could you provide a little more information about what you're doing inside your PHP script so that we can try to reproduce the problem in house?  For example, is this a basic script (in terms of database interaction) and with each invocation from the browser the amount of memory in use by the process increases?  Or is this problem occurring in a single call to a long running script?

    What are your FastCGI settings from C:\Windows\System32\inetsrv\config\applicationHost.config?

    To help with the garbage collection, please make sure you are calling sqlsrv_free_stmt and sqlsrv_close within your script.  The resources for the statement and connection should be freed automatically by PHP when the script ends, but calling those functions explicitly from within your script may help, given the behavior you're seeing.

    David Sceppa
    Program Manager - Microsoft SQL Server Driver for PHP

    Tuesday, April 7, 2009 5:31 PM
  • Hi David, the website in question is http://zena-in.cz/ with about 10.000 unique visitors and 300.000 to 500.000 pageviews per day. It is a very heavy website with millions of SQL queries per hour. Each page might take 50 or even more SQL queries to render (if it does not come from cache, which means just 1-2 SQL queries to retrieve the cache). We explicitly call sqlsrv_close() as PHP shutdown function, we do NOT usually call sqlsrv_free_stmt() for queries done with a procedure, where variables have limited lifespan. PHP should take care of that.

    SQL server 2008 has its own HW, connected by 1Gb local network to primary IIS7 server.

    As for FastCGI settings - having instanceMaxRequests set at recommended 10.000 ment extremely fast growth of memory usage (from 30MB to 300MB per one php-cgi.exe within 2 hours), but these modified settings can last whole day, before IIS7 is restarted at 03:00am and memory consumption drops:

            <fastCgi>
                <application fullPath="D:\PHP\php-cgi.exe" maxInstances="8" idleTimeout="120" activityTimeout="30" requestTimeout="30" instanceMaxRequests="1000" flushNamedPipe="true">
                    <environmentVariables>
                        <environmentVariable name="PHP_FCGI_MAX_REQUESTS" value="1000" />
                        <environmentVariable name="PHP_FCGI_CHILDREN" value="0" />
                    </environmentVariables>
                </application>
            </fastCgi>
    Tuesday, April 7, 2009 5:36 PM
  • Hi Radek,

     

    We started to investigate the memory leak that you reported, but we need one additional clarification from you.  I gather from your last post that despite lowering the recycle interval for FastCGI (via a lower value for “instanceMaxRequests”), you notice a continuous increase in the IIS memory consumption (throughout the day). Is my statement correct?

     

    We would have expected that in the event we have a memory leak in the driver, the shorter recycle time would take care of it. Once a FastCGI instance is recycled, all its accumulated memory is flushed.

     

    Thank you,

    Serban


    Serban Iliescu - MSFT
    • Marked as answer by David Sceppa Wednesday, April 15, 2009 9:45 PM
    Wednesday, April 8, 2009 6:07 PM
    Answerer
  • Hi Serban, shorter recycle cycle -does- take care of it. That is why I have changed it from 10.000 to 1.000. We still force IIS7 restart at 3am, but that is probably not necessary.It makes no harm either.

    I mean, you can still see (in task manager) php-cgi.exe processes slowly allocating more and more memory, but being reset soon after that.
    Wednesday, April 8, 2009 6:09 PM
  • Radek,

    Thanks again for reporting the issue.  Serban's working to reproduce the issue in house so we can take a closer look.  In the meantime, I'm glad to hear that the shorter recycle setting helps resolve the problem in the meantime.  I'm marking his response as an answer so other forum readers can find his response more easily as we continue to investigate.

    David Sceppa
    Program Manager - Microsoft SQL Server Driver for PHP
    Wednesday, April 15, 2009 9:45 PM
  • Hi Serban, shorter recycle cycle -does- take care of it. That is why I have changed it from 10.000 to 1.000. We still force IIS7 restart at 3am, but that is probably not necessary.It makes no harm either.

    I mean, you can still see (in task manager) php-cgi.exe processes slowly allocating more and more memory, but being reset soon after that.

    Could you give more details? Where can I find the related documentation?
    Thursday, October 28, 2010 8:17 AM
  • Godfery-

    There is information about setting the FastCGI "instance maxRequests" setting here: http://www.iis.net/ConfigReference/system.webServer/fastCgi. Let me know if that doesn't provide the detail you are looking for.

    Are you asking because you are seeing the same issue described in this thread?

    Thanks.

    -Brian


    This posting is provided "AS IS" with no warranties, and confers no rights. http://blogs.msdn.com/brian_swan
    Thursday, October 28, 2010 4:17 PM