ID:               45161
 User updated by:  humbads at alum dot mit dot edu
-Summary:          reusing a curl handle leaks memory
 Reported By:      humbads at alum dot mit dot edu
 Status:           Open
 Bug Type:         cURL related
 Operating System: FreeBSD 6.2, Windows XP SP3
 PHP Version:      5.2.6
 New Comment:

Below is the r.php script.  When testing this bug report, please use
this script (or some other URL) so my poor server does not get
hammered.

<?php
// This script runs a variable amount of time
// and generates a variable amount of data

// Output a random number of blank space
$s = microtime(true);
$m = rand(100,200);
$bytes = 0;
for($i = 0; $i < $m; $i++) {
        $message = "         \n";
        print $message;
        $bytes += strlen($message);
        usleep(10);
}

// Print time taken and the value of the "echo" parameter
print isset($_REQUEST['echo']) ? 'echo: '.$_REQUEST['echo'].' ' : "";
print $bytes.' bytes ';
print " in ";
print round(microtime(true) - $s, 4)." seconds";
exit();
?>


Previous Comments:
------------------------------------------------------------------------

[2008-06-03 15:04:41] humbads at alum dot mit dot edu

Description:
------------
Reusing a curl handle for multiple requests leaks memory.  It leaks
about 100 bytes per request.  This is a problem when making a large
number of requests using the same handle.  Libcurl documentation says to
always reuse the handle when possible in order to reuse connections. 
The bug occurs on Windows XP/IIS and Apache/FreeBSD 6.2.

Reproduce code:
---------------
<?php
// Reuse curl handle memory leak test
$ch = curl_init();
$startmem = memory_get_usage();
for($i = 0; $i < 100; $i++) {
  $fp = fopen('/dev/null', "w");
  curl_setopt($ch, CURLOPT_URL,
    'http://debug.atensoftware.com/r.php?echo='.rand());
  curl_setopt($ch, CURLOPT_FILE, $fp);
  curl_exec($ch);

  fclose($fp);
  unset($fp);
  print "$i-mem: ".(memory_get_usage() - $startmem)." bytes\n";
}

?>

Expected result:
----------------
The memory usage should not increase after each request.



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


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

Reply via email to