|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-10-04 14:08 UTC] eugen at id dot com dot ua
Description: ------------ Possible memory leaks when using curl_multi_* functions. I start 10 tasks with curl_multi and at completion of one of them add a new task. The use of memory is gradually increased thus, although $GLOBALS has a permanent size approximately. In particular, at the call of curl_close() or curl_multi_remove_handle() memory is not freed (I guess it should be...) Reproduce code: --------------- http://www.follow.net.ua/bug.phps (see MEMORY_IS_NOT_RELEASED_HERE string near the end of file). Expected result: ---------------- Downloading queue of documents with 10 threads Actual result: -------------- Gradual increasing of memory usage (sizeof $GLOBALS is *NOT* increasing) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 25 19:00:02 2025 UTC |
I've commited a small patche which decreases refcount for curl handles added to the multi handle (previously they were destroyed on shutdown). The patch will appear in the next snapshot. Thanks you for your help. Meanwhile lets look into your code: $curl_handles[ $index ] = $cid; // refcount++ ... if ($handle == $info['handle']) { // refcount++ ... curl_close($info['handle']); // refcount-- 1 + 1 - 1 = 1, so curl_close() doesn't actually destroy the handle, but just reduces its refcount. To destroy the handles you need to unset() numerous arrays they were added to. ..Or you can put this code into a function, this way all variables will be destroyed automatically when execution goes out of the scope. Also, notice that curl_close() IS NOT called for the last handle, because $active is false at the moment.In php5.2 2006-10-06 06:30 snapshot problem is not solved. Even this code, where each handle is destroyed after use doesn't release memory: <?php $tasks = array("http://www.google.com","http://www.php.net"); $mh = curl_multi_init(); reset($tasks); while (list($index, $row)=each($tasks)) { $cid = curl_init($row); curl_setopt($cid, CURLOPT_RETURNTRANSFER, 1); curl_multi_add_handle($mh, $cid); unset($cid); // unset curl handle } do { $n = curl_multi_exec($mh, $active); $info = curl_multi_info_read($mh); if (!empty($info)) { $memory_usage = memory_get_usage(); // this should free up resources curl_close($info['handle']); $diff = memory_get_usage() - $memory_usage; echo "Memory usage was: $memory_usage, after curl_close: $diff bytes more\n"; } unset($info); } while ($active); ?> > Meanwhile lets look into your code ... Does it matter how much refs for curl connection I have? Lets look at curl_close documentation (http://ua2.php.net/manual/en/function.curl-close.php): This function closes a CURL session and (!!!)frees all resources(!!!). There's nothing abount refcounts. P.S. In submitted script curl releases memory when after while loop is finished I call curl_multi_init() again. %|