开发者

PHP cURL, memory leak when using CURLOPT_RETURNTRANSFER

开发者 https://www.devze.com 2023-01-31 09:43 出处:网络
The following code is in a loop. 开发者_JAVA技巧Each loop changes $URI to a new address. My problem is that each pass takes up more and more memory.

The following code is in a loop. 开发者_JAVA技巧Each loop changes $URI to a new address. My problem is that each pass takes up more and more memory.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URI);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$res = curl_exec($ch);
curl_close($ch);

I finally worked out that if I comment out the CURLOPT_RETURNTRANSFER line the leak stops.

I use "CURLOPT_RETURNTRANSFER, true" so I can get the result of the cURL operation as a string to parse. But, it would appear that the memory used to store this string is not parsed with each pass. Can anyone suggest a way to clear this buffer and recover the used memory? Is there a destructor I could use, I've tried __destruct() but can't seem to get the syntax right.

Thanks C


Version 5.1.6 of PHP seems to have an issue with memory leaking when using "CURLOPT_RETURNTRANSFER, true" to store the results of the cURL as a string. Upgrading to 5.3 sorted the leak out for me.

Thanks

0

精彩评论

暂无评论...
验证码 换一张
取 消