|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-06-03 15:04 UTC] 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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 22:00:01 2025 UTC |
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(); ?>