PHP cURL,使用CURLOPT_RETURNTRANSFER时的内存泄漏 [英] PHP cURL, memory leak when using CURLOPT_RETURNTRANSFER

查看:421
本文介绍了PHP cURL,使用CURLOPT_RETURNTRANSFER时的内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码处于循环中。每个循环将$ URI更改为一个新地址。
我的问题是每个pass都会占用更多的内存。

The following code is in a loop. 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);

我终于找出了如果我注释掉CURLOPT_RETURNTRANSFER行,泄漏就会停止。

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

我使用CURLOPT_RETURNTRANSFER,true,所以我可以得到cURL操作的结果作为一个字符串来解析。但是,看起来用于存储此字符串的内存不会在每次传递时解析。
任何人都可以建议一种方法来清除这个缓冲区和恢复使用的内存?有没有一个析构函数我可以使用,我试过__destruct(),但似乎不能得到正确的语法。

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.

谢谢
C

推荐答案

使用CURLOPT_RETURNTRANSFER,true存储cURL的结果时,PHP 5.1.6版本似乎有内存泄漏的问题作为字符串。
升级到5.3为我排序泄漏。

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.

感谢

这篇关于PHP cURL,使用CURLOPT_RETURNTRANSFER时的内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆