Edit report at https://bugs.php.net/bug.php?id=60570&edit=1
ID: 60570
Comment by: roberto at spadim dot com dot br
Reported by: roberto at spadim dot com dot br
Summary: memory leak with create context
Status: Verified
Type: Bug
Package: Streams related
Operating System: LINUX
PHP Version: 5.3.8
Block user comment: N
Private report: N
New Comment:
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,,,,,)));
Previous Comments:
------------------------------------------------------------------------
[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