Memory leak when reusing curl-handle
| Bug #63859 | Memory leak when reusing curl-handle | ||||
|---|---|---|---|---|---|
| Submitted: | 2012-12-27 08:59 UTC | Modified: | - | ||
| From: | jille at hexon dot cx | Assigned: | |||
| Status: | Closed | Package: | cURL related | ||
| PHP Version: | 5.4.10 | OS: | Linux | ||
| Private report: | No | CVE-ID: | None | ||
[2012-12-27 08:59 UTC] jille at hexon dot cx
Description:
------------
PHP (or libcurl, I'm afraid I don't know where exactly the problem lies) seems to leak memory when using the same curl-handle for multiple requests.
The test script below reports the same memory_get_usage()-value for the first 300 requests and a 25% increase after but top(1) reports the memory grows up to 100MB when the script is done.
Uncommenting the resetting of CURLOPT_POSTFIELDS doesn't seem to help. Uncommenting the recreation of $ch prevents the memory from being leaked.
Test script:
---------------
<?php
$ch = curl_init('http://some-domain.com/dump.html');
for($i = 0; 1000 > $i; $i++) {
# $ch = curl_init('http://some-domain.com/dump.html');
$post = array();
$post['data'] = base64_encode(str_repeat(hash('sha256', uniqid()), 1000));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
# curl_setopt($ch, CURLOPT_POSTFIELDS, '');
if($i % 100 == 0) {
var_dump(memory_get_usage(true));
}
}
?>
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2014-01-13 20:29 UTC] artur77 at freemail dot hu