Edit report at https://bugs.php.net/bug.php?id=60570&edit=1

 ID:                 60570
 Updated by:         cataphr...@php.net
 Reported by:        roberto at spadim dot com dot br
 Summary:            memory leak with create context
-Status:             Verified
+Status:             Closed
 Type:               Bug
 Package:            Streams related
 Operating System:   LINUX
 PHP Version:        5.3.8
-Assigned To:        
+Assigned To:        cataphract
 Block user comment: N
 Private report:     N

 New Comment:

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.




Previous Comments:
------------------------------------------------------------------------
[2011-12-21 15:44:35] cataphr...@php.net

Automatic comment from SVN on behalf of cataphract
Revision: http://svn.php.net/viewvc/?view=revision&revision=321298
Log: - Fixed bug #60570 (http wrapper leaks context resource if request fails/is
  redirected).

------------------------------------------------------------------------
[2011-12-21 15:36:03] 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:07:41] cataphr...@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:03:29] 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-20 05:20:49] 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...


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



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

Reply via email to