[英]curl_close will clean up the return result of curl_exec
I surely confirm the result of curl_exec will be cleaned up by curl_close. 我肯定会确认curl_exec的结果会被curl_close清理掉。
I have to comment out the curl_close line to get the result.My php version is 5.3.8. 我必须注释掉curl_close行才能得到结果。我的php版本是5.3.8。
How do I get result with curl_close? 如何使用curl_close获得结果? Here is my code 这是我的代码
function curl_get_contents($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$r = curl_exec($ch);
//curl_close($ch);
return $r;
}
It has no effect on the return value, as long as the data from curl_exec();
只要curl_exec();
的数据, curl_exec();
返回值没有影响curl_exec();
is stored in $r
you can return as you like. 存储在$r
您可以根据需要返回。
This works normally. 这正常工作。
function curl_get_contents($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$r = curl_exec($ch);
curl_close($ch);
return $r;
}
$returnedValue = curl_get_contents($url); //Holds the contents
Edit as Marc B pointed out : 编辑为Marc B指出:
You don't need to do a curl close. 您无需卷翘。 PHP will clean up for you when the function returns and $ch goes out-of-scope. 当函数返回并且$ ch超出范围时,PHP将为您清理。
Hence there's no point of even closing it, but it shouldn't happen. 因此,即使关闭它也没有意义,但不应该发生。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.