php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60570 memory leak with create context
Submitted: 2011-12-20 05:20 UTC Modified: 2011-12-21 15:45 UTC
From: roberto at spadim dot com dot br Assigned: cataphract (profile)
Status: Closed Package: Streams related
PHP Version: 5.3.8 OS: LINUX
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: roberto at spadim dot com dot br
New email:
PHP Version: OS:

 

 [2011-12-20 05:20 UTC] roberto at spadim dot com dot br
Description:
------------
hi, when i create a context inside a function i see a memory leak, but when i create it in the main source code line, i don´t see it...
please check the script..

i think the problem is something that don´t leave memory get back when destroying context variable

Test script:
---------------
memory leak:
<?php
function g(){
        $context=stream_context_create(array('http'=>array('timeout'=>1)));
        $ret=file_get_contents('http://172.17.0.5/not_found',0,$context);
        unset($context);
        return($ret);
}
        $base=memory_get_usage();
        while(1){
                g();
                usleep(50000);
                echo    (memory_get_usage()-$base)."\n";
// memory get bigger and bigger here....
        }
?>

memory leak too:
<?php
        $base=memory_get_usage();
        while(1){
                $context= stream_context_create(array('http'=>array('timeout'=>1)));
                $ret=file_get_contents('http://172.17.0.5/not_found',0,$context);
                usleep(50000);unset($ret,$context);
                echo    (memory_get_usage()-$base)."\n";
// memory get bigger and bigger...
        }
?>


nice:
<?php
        $base=memory_get_usage();
        $context= stream_context_create(array('http'=>array('timeout'=>1)));
        while(1){
                $ret=file_get_contents('http://172.17.0.5/not_found',0,$context);
                usleep(50000);unset($ret);
                echo    (memory_get_usage()-$base)."\n";
// memory is nice here...
        }
?>



Expected result:
----------------
NICE:
Warning...
3552
Warning...
3552
Warning...
3552
Warning...
3552
Warning...
3552
Warning...
3552


MEMORY LEAK:
Warning...
40120
Warning...
41344
Warning...
42568
Warning...
43792


Actual result:
--------------
well i think that others fields explain...

MEMORY LEAK:
Warning...
40120
Warning...
41344
Warning...



(+- 1224 per while interaction)

i don´t know how to solve this, unset don´t work, =null don´t work, and i don´t find a function to destroy contexts...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-21 14:55 UTC] cataphract@php.net
-Status: Open +Status: Verified
 [2011-12-21 15:03 UTC] roberto at spadim dot com dot br
maybe the array parameters isn´t being removed from memory? i tryed to change code 
inserting a comma after timeout parameter "'timeout'=>1," and it add more memory 
leak per interaction more commas = more memory leak
 $context= stream_context_create(array('http'=>array('timeout'=>1,,,,,)));
 [2011-12-21 15:07 UTC] cataphract@php.net
The problem is simply that the context resource leaks everytime the http request fails. Seems to have been introduce in r262454.
 [2011-12-21 15:36 UTC] roberto at spadim dot com dot br
it´s  a bit strange since if i don´t create a new context (calling a function or creating a new context) the memory leak don´t occur
well, if the problem was founded that´s ok :) i´m just waiting something to solve it
i´m changing ini varible to change http timeout and not using contexts while no other workaround is founded
 [2011-12-21 15:44 UTC] cataphract@php.net
Automatic comment from SVN on behalf of cataphract
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=321298
Log: - Fixed bug #60570 (http wrapper leaks context resource if request fails/is
  redirected).
 [2011-12-21 15:45 UTC] cataphract@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2011-12-21 15:45 UTC] cataphract@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: cataphract
 [2011-12-21 15:51 UTC] roberto at spadim dot com dot br
ok i will test it soon
no problem :) i helped before and i won´t stop helping :)
thanks guys your are wellcome
 [2012-04-18 09:46 UTC] laruence@php.net
Automatic comment on behalf of cataphract
Revision: http://git.php.net/?p=php-src.git;a=commit;h=d1be77edfb72df9481dac662aca770f08c90ec92
Log: - Fixed bug #60570 (http wrapper leaks context resource if request fails/is   redirected).
 [2012-07-24 23:38 UTC] rasmus@php.net
Automatic comment on behalf of cataphract
Revision: http://git.php.net/?p=php-src.git;a=commit;h=d1be77edfb72df9481dac662aca770f08c90ec92
Log: - Fixed bug #60570 (http wrapper leaks context resource if request fails/is   redirected).
 [2013-11-17 09:34 UTC] laruence@php.net
Automatic comment on behalf of cataphract
Revision: http://git.php.net/?p=php-src.git;a=commit;h=d1be77edfb72df9481dac662aca770f08c90ec92
Log: - Fixed bug #60570 (http wrapper leaks context resource if request fails/is   redirected).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 19:01:30 2024 UTC