<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How to use curl_multi() without blocking</title>
	<atom:link href="http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/</link>
	<description>a blog about building stuff on the web</description>
	<lastBuildDate>Mon, 09 Jan 2012 18:55:04 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
	<item>
		<title>By: Michael</title>
		<link>http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/comment-page-1/#comment-4572</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Fri, 16 Dec 2011 23:47:48 +0000</pubDate>
		<guid isPermaLink="false">http://onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/#comment-4572</guid>
		<description>Ok. I got it implemented using a hash tag to pass the monitor id and then getting this value from the $request ($info[&#039;url&#039;] doesn&#039;t retain the hash tag on the URL for whatever reason). This way, by using a hash tag, I figure there is no possibility that it&#039;ll ever change the URL that is checked. Still it&#039;d be cool, if RollingCurl had a way to pass a value without affecting the URL. But this is working for now. Thanks for sharing RC! </description>
		<content:encoded><![CDATA[<p>Ok. I got it implemented using a hash tag to pass the monitor id and then getting this value from the $request ($info[&#039;url&#039;] doesn&#039;t retain the hash tag on the URL for whatever reason). This way, by using a hash tag, I figure there is no possibility that it&#039;ll ever change the URL that is checked. Still it&#039;d be cool, if RollingCurl had a way to pass a value without affecting the URL. But this is working for now. Thanks for sharing RC!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Fraser</title>
		<link>http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/comment-page-1/#comment-4564</link>
		<dc:creator>Josh Fraser</dc:creator>
		<pubDate>Tue, 13 Dec 2011 21:13:20 +0000</pubDate>
		<guid isPermaLink="false">http://onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/#comment-4564</guid>
		<description>Sure, an easy way to do this is to add a GET variable to the end of the URL you are fetching (ie. ?mysql_id=42) and then parse out that ID when the request completes from the CURL info array. </description>
		<content:encoded><![CDATA[<p>Sure, an easy way to do this is to add a GET variable to the end of the URL you are fetching (ie. ?mysql_id=42) and then parse out that ID when the request completes from the CURL info array.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/comment-page-1/#comment-4563</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Tue, 13 Dec 2011 20:26:40 +0000</pubDate>
		<guid isPermaLink="false">http://onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/#comment-4563</guid>
		<description>Hey Josh,  
 
 Is it possible to pass a value (e.g. $row[&#039;id&#039;]) into RollingCurl so that it&#039;s available for use within the callback function? 
 
foreach ($rows as $row) { 
    // Add each request to the RollingCurl object. 
    $request = new RollingCurlRequest($row[&#039;url&#039;]); 
    $rc-&gt;add($request); 
} 
 
(Basically, it&#039;s the MySQL primary key for each row ($row[&#039;id&#039;]) that I&#039;m trying to pass and make available within the callback function.) 
 
Thanks. 
 </description>
		<content:encoded><![CDATA[<p>Hey Josh,  </p>
<p> Is it possible to pass a value (e.g. $row[&#039;id&#039;]) into RollingCurl so that it&#039;s available for use within the callback function? </p>
<p>foreach ($rows as $row) {<br />
    // Add each request to the RollingCurl object.<br />
    $request = new RollingCurlRequest($row[&#039;url&#039;]);<br />
    $rc-&gt;add($request);<br />
} </p>
<p>(Basically, it&#039;s the MySQL primary key for each row ($row[&#039;id&#039;]) that I&#039;m trying to pass and make available within the callback function.) </p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yaffle</title>
		<link>http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/comment-page-1/#comment-3343</link>
		<dc:creator>Yaffle</dc:creator>
		<pubDate>Sat, 05 Nov 2011 05:42:00 +0000</pubDate>
		<guid isPermaLink="false">http://onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/#comment-3343</guid>
		<description>Hello! Great article! 
I wrote simple class with similar functionality, i use anonymous functions for callbacks:  &lt;a href=&quot;https://github.com/Yaffle/MultiGet&quot; rel=&quot;nofollow&quot;&gt;https://github.com/Yaffle/MultiGet&lt;/a&gt; 
 </description>
		<content:encoded><![CDATA[<p>Hello! Great article!<br />
I wrote simple class with similar functionality, i use anonymous functions for callbacks:  <a href="https://github.com/Yaffle/MultiGet" rel="nofollow">https://github.com/Yaffle/MultiGet</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Fraser</title>
		<link>http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/comment-page-1/#comment-3165</link>
		<dc:creator>Josh Fraser</dc:creator>
		<pubDate>Fri, 08 Jul 2011 19:53:55 +0000</pubDate>
		<guid isPermaLink="false">http://onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/#comment-3165</guid>
		<description>Ah, good catch.  Yes, you probably want to close those.  
 
I haven&#039;t tried reusing the connections, or at least I don&#039;t remember experimenting with that.  Would be interesting to see if you can make that work.  If you do, please post your results here so others can gain from them. 
 
Thanks! </description>
		<content:encoded><![CDATA[<p>Ah, good catch.  Yes, you probably want to close those.  </p>
<p>I haven&#039;t tried reusing the connections, or at least I don&#039;t remember experimenting with that.  Would be interesting to see if you can make that work.  If you do, please post your results here so others can gain from them. </p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: C4rter</title>
		<link>http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/comment-page-1/#comment-3164</link>
		<dc:creator>C4rter</dc:creator>
		<pubDate>Thu, 07 Jul 2011 19:02:30 +0000</pubDate>
		<guid isPermaLink="false">http://onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/#comment-3164</guid>
		<description>Hi Josh, 
 
I&#039;m using your nice piece of code for a lot of data (3.5 million requests). 
My rolling window is 10. 
But after a while my working machine is out of memory. 
 
I&#039;m trying to find the memory leak and I noticed you don&#039;t close the single curl handles. 
I think, after 
curl_multi_remove_handle($master, $done[&#039;handle&#039;]); 
you have to call 
curl_close($done[&#039;handle&#039;]);  
to totally close the handle, because 
curl_multi_close($master); 
closes the master but not the single handles. 
 
And can you explain me, why you have to &quot;// start a new request&quot; if you just startet all of the requests in the &quot;for&quot; loop? </description>
		<content:encoded><![CDATA[<p>Hi Josh, </p>
<p>I&#039;m using your nice piece of code for a lot of data (3.5 million requests).<br />
My rolling window is 10.<br />
But after a while my working machine is out of memory. </p>
<p>I&#039;m trying to find the memory leak and I noticed you don&#039;t close the single curl handles.<br />
I think, after<br />
curl_multi_remove_handle($master, $done[&#039;handle&#039;]);<br />
you have to call<br />
curl_close($done[&#039;handle&#039;]);<br />
to totally close the handle, because<br />
curl_multi_close($master);<br />
closes the master but not the single handles. </p>
<p>And can you explain me, why you have to &quot;// start a new request&quot; if you just startet all of the requests in the &quot;for&quot; loop?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wahabeel</title>
		<link>http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/comment-page-1/#comment-1478</link>
		<dc:creator>wahabeel</dc:creator>
		<pubDate>Sun, 05 Dec 2010 12:11:00 +0000</pubDate>
		<guid isPermaLink="false">http://onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/#comment-1478</guid>
		<description>Parse error: syntax error, unexpected &#039;;&#039; in /home/migcybe1/public_html/php/multi_eksekusi_3.php on line 6 
when i test this script  
&lt;?php 
function rolling_curl($urls, $callback, $custom_options = null) { 
 
    // make sure the rolling window isn&#039;t greater than the # of urls 
    $rolling_window = 5; 
    $rolling_window = (sizeof($urls) &lt; $rolling_window) ? sizeof($urls) : $rolling_window; 
 
    $master = curl_multi_init(); 
    $curl_arr = array(); 
 
    // add additional curl options here 
    $std_options = array(CURLOPT_RETURNTRANSFER =&gt; true, 
    CURLOPT_FOLLOWLOCATION =&gt; true, 
    CURLOPT_MAXREDIRS =&gt; 5); 
    $options = ($custom_options) ? ($std_options + $custom_options) : $std_options; 
 
    // start the first batch of requests 
    for ($i = 0; $i &lt; $rolling_window; $i++) { 
        $ch = curl_init(); 
        $options[CURLOPT_URL] = $urls[$i]; 
        curl_setopt_array($ch,$options); 
        curl_multi_add_handle($master, $ch); 
    } 
 
    do { 
        while(($execrun = curl_multi_exec($master, $running)) == CURLM_CALL_MULTI_PERFORM); 
        if($execrun != CURLM_OK) 
            break; 
        // a request was just completed -- find out which one 
        while($done = curl_multi_info_read($master)) { 
            $info = curl_getinfo($done[&#039;handle&#039;]); 
            if ($info[&#039;http_code&#039;] == 200)  { 
                $output = curl_multi_getcontent($done[&#039;handle&#039;]); 
 
                // request successful.  process output using the callback function. 
                $callback($output); 
 
                // start a new request (it&#039;s important to do this before removing the old one) 
                $ch = curl_init(); 
                $options[CURLOPT_URL] = $urls[$i++];  // increment i 
                curl_setopt_array($ch,$options); 
                curl_multi_add_handle($master, $ch); 
 
                // remove the curl handle that just completed 
                curl_multi_remove_handle($master, $done[&#039;handle&#039;]); 
            } else { 
                // request failed.  add error handling. 
            } 
        } 
    } while ($running); 
     
    curl_multi_close($master); 
    return true; 
} 
?&gt; 
how to solve it??? thanks </description>
		<content:encoded><![CDATA[<p>Parse error: syntax error, unexpected &#039;;&#039; in /home/migcybe1/public_html/php/multi_eksekusi_3.php on line 6<br />
when i test this script<br />
&lt;?php<br />
function rolling_curl($urls, $callback, $custom_options = null) { </p>
<p>    // make sure the rolling window isn&#039;t greater than the # of urls<br />
    $rolling_window = 5;<br />
    $rolling_window = (sizeof($urls) &amp;lt; $rolling_window) ? sizeof($urls) : $rolling_window; </p>
<p>    $master = curl_multi_init();<br />
    $curl_arr = array(); </p>
<p>    // add additional curl options here<br />
    $std_options = array(CURLOPT_RETURNTRANSFER =&amp;gt; true,<br />
    CURLOPT_FOLLOWLOCATION =&amp;gt; true,<br />
    CURLOPT_MAXREDIRS =&amp;gt; 5);<br />
    $options = ($custom_options) ? ($std_options + $custom_options) : $std_options; </p>
<p>    // start the first batch of requests<br />
    for ($i = 0; $i &amp;lt; $rolling_window; $i++) {<br />
        $ch = curl_init();<br />
        $options[CURLOPT_URL] = $urls[$i];<br />
        curl_setopt_array($ch,$options);<br />
        curl_multi_add_handle($master, $ch);<br />
    } </p>
<p>    do {<br />
        while(($execrun = curl_multi_exec($master, $running)) == CURLM_CALL_MULTI_PERFORM);<br />
        if($execrun != CURLM_OK)<br />
            break;<br />
        // a request was just completed &#8212; find out which one<br />
        while($done = curl_multi_info_read($master)) {<br />
            $info = curl_getinfo($done[&#039;handle&#039;]);<br />
            if ($info[&#039;http_code&#039;] == 200)  {<br />
                $output = curl_multi_getcontent($done[&#039;handle&#039;]); </p>
<p>                // request successful.  process output using the callback function.<br />
                $callback($output); </p>
<p>                // start a new request (it&#039;s important to do this before removing the old one)<br />
                $ch = curl_init();<br />
                $options[CURLOPT_URL] = $urls[$i++];  // increment i<br />
                curl_setopt_array($ch,$options);<br />
                curl_multi_add_handle($master, $ch); </p>
<p>                // remove the curl handle that just completed<br />
                curl_multi_remove_handle($master, $done[&#039;handle&#039;]);<br />
            } else {<br />
                // request failed.  add error handling.<br />
            }<br />
        }<br />
    } while ($running); </p>
<p>    curl_multi_close($master);<br />
    return true;<br />
}<br />
?&gt;<br />
how to solve it??? thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Fraser</title>
		<link>http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/comment-page-1/#comment-1283</link>
		<dc:creator>Josh Fraser</dc:creator>
		<pubDate>Sat, 30 Oct 2010 20:22:13 +0000</pubDate>
		<guid isPermaLink="false">http://onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/#comment-1283</guid>
		<description>Ah, great question.  The trick here is to make $maindir a global variable inside your callback like this: 
 
function callback($result) { 
    global $maindir; 
    ... 
} </description>
		<content:encoded><![CDATA[<p>Ah, great question.  The trick here is to make $maindir a global variable inside your callback like this: </p>
<p>function callback($result) {<br />
    global $maindir;<br />
    &#8230;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: @xaluan</title>
		<link>http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/comment-page-1/#comment-1282</link>
		<dc:creator>@xaluan</dc:creator>
		<pubDate>Sat, 30 Oct 2010 05:20:58 +0000</pubDate>
		<guid isPermaLink="false">http://onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/#comment-1282</guid>
		<description>I&#039;m not php expert and looking for solution to download multi images in one time..I&#039;m not php expert and looking for solution to download multi images in one time.. 
this class look like work for me but i dont know how to work it out for saving files. at defined directory: 
 
eg: 
$imgs = array(&quot;http://l.yimg.com/a/i/us/pim/dclient/cg504_5/img/md5/509840ceb0dd52f5f024dba77099b4b0_1.gif&quot;, 
              &quot;http://www.onlineaspect.com/wp-content/themes/onlineaspect/images/lego.png&quot;); 
 
save to  
$maindir = &quot;images&quot;; 
$dirs = array ($maindir .&quot;/yahoo&quot;, $maindir .&quot;/onlineaspect&quot;); 
 
i dont kow how to pass var dir to callback to save each images to directoy  
thanks for any example 
 </description>
		<content:encoded><![CDATA[<p>I&#039;m not php expert and looking for solution to download multi images in one time..I&#039;m not php expert and looking for solution to download multi images in one time..<br />
this class look like work for me but i dont know how to work it out for saving files. at defined directory: </p>
<p>eg:<br />
$imgs = array(&quot;<a href="http://l.yimg.com/a/i/us/pim/dclient/cg504_5/img/md5/509840ceb0dd52f5f024dba77099b4b0_1.gif&quot;" rel="nofollow">http://l.yimg.com/a/i/us/pim/dclient/cg504_5/img/md5/509840ceb0dd52f5f024dba77099b4b0_1.gif&quot;</a>,<br />
              &quot;<a href="http://www.onlineaspect.com/wp-content/themes/onlineaspect/images/lego.png&#038;quot" rel="nofollow">http://www.onlineaspect.com/wp-content/themes/onlineaspect/images/lego.png&#038;quot</a> <img src='http://www.onlineaspect.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ; </p>
<p>save to<br />
$maindir = &quot;images&quot;;<br />
$dirs = array ($maindir .&quot;/yahoo&quot;, $maindir .&quot;/onlineaspect&quot;); </p>
<p>i dont kow how to pass var dir to callback to save each images to directoy<br />
thanks for any example</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: islam</title>
		<link>http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/comment-page-1/#comment-1265</link>
		<dc:creator>islam</dc:creator>
		<pubDate>Thu, 21 Oct 2010 21:09:25 +0000</pubDate>
		<guid isPermaLink="false">http://onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/#comment-1265</guid>
		<description>t&#039;s important to do this before removing the old one </description>
		<content:encoded><![CDATA[<p>t&#039;s important to do this before removing the old one</p>
]]></content:encoded>
	</item>
</channel>
</rss>

