在curl_exec中使用最少的RAM

问题描述:

能否告诉我哪些代码示例使用最少的RAM?这里是我的两个例子:在curl_exec中使用最少的RAM

$ch = curl_init(); 

foreach ($URLS as $url){ 
    // set URL and other appropriate options 
    curl_setopt($ch, CURLOPT_URL, $url.'&no_cache'); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 

    // grab URL and pass it to the browser 
    curl_exec($ch); 
} 
// close cURL resource, and free up system resources 
curl_close($ch); 

foreach ($URLS as $url){ 
    $ch = curl_init(); 
    // set URL and other appropriate options 
    curl_setopt($ch, CURLOPT_URL, $url.'&no_cache'); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 

    // grab URL and pass it to the browser 
    curl_exec($ch); 
      curl_close($ch); 
} 
// close cURL resource, and free up system resources 
+0

*更好*是一个令人难以置信的模糊词在这里使用。你是指什么意思*更好*? – Nick 2011-04-04 16:14:38

+0

RAM的用法... – 2011-04-04 16:26:41

+0

您的问题现在得到了解答,但我已经编辑了您的标题和问题格式,以便更好地表达您对期待的答案的期望;) – Nick 2011-04-04 16:40:08

第一个具有更轻的开销,因为你只实例化对象卷曲一次,但如果卷曲中有任何泄漏,而你取大量的网址,你可能会用完内存。

通常我只调用一个新的curl对象,如果下一个要获取的url在设置上与旧的curl有太多差异。更容易启动默认设置并从中进行更改,而不是尝试从上一次运行中“撤消”冲突设置。