<?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>Fri, 05 Mar 2010 04:15:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Jack Fuchs</title>
		<link>http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/comment-page-1/#comment-868</link>
		<dc:creator>Jack Fuchs</dc:creator>
		<pubDate>Mon, 22 Feb 2010 21:05:19 +0000</pubDate>
		<guid isPermaLink="false">http://onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/#comment-868</guid>
		<description>Any ideas on referencing the requests to the responses? 
 
I need a response to be identifiable after it fulfilled a request. </description>
		<content:encoded><![CDATA[<p>Any ideas on referencing the requests to the responses? </p>
<p>I need a response to be identifiable after it fulfilled a request.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: no english</title>
		<link>http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/comment-page-1/#comment-849</link>
		<dc:creator>no english</dc:creator>
		<pubDate>Wed, 03 Feb 2010 10:12:30 +0000</pubDate>
		<guid isPermaLink="false">http://onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/#comment-849</guid>
		<description>I would like to add two attributes (public $ response; public $ output;), when no callback function to facilitate the use of external processing, thank you.
Sorry, my English Henlan, and use Google Translation</description>
		<content:encoded><![CDATA[<p>I would like to add two attributes (public $ response; public $ output;), when no callback function to facilitate the use of external processing, thank you.<br />
Sorry, my English Henlan, and use Google Translation</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric P</title>
		<link>http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/comment-page-1/#comment-848</link>
		<dc:creator>Eric P</dc:creator>
		<pubDate>Sun, 31 Jan 2010 19:33:01 +0000</pubDate>
		<guid isPermaLink="false">http://onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/#comment-848</guid>
		<description>I need to access Rolling Curl results based on specific URL sequencing. 
 
For smaller requests, I&#039;m using the code below and it&#039;s working fine. 
 
For larger requests, I could write the results to disk with sequential file naming for post sequential compilation, rather than storing all the results in memory. 
 
I&#039;m thinking the best way to handle it dynamically, would be to create a function to write sequentially named files to disk, based on a defined size/memory threshold, otherwise, handle via an in-memory associative array as below. 
 
Thoughts? 
 
function request_callback($response,$info) { 
    global $rc_result ; 
    // get last character of URL to enable indexing of results 
    // e.g., $url[] = &lt;a href=&quot;http://mydomain.com?request=1,&quot; target=&quot;_blank&quot;&gt;http://mydomain.com?request=1,&lt;/a&gt; $url[] = &lt;a href=&quot;http://mydomain.com?request=2&quot; target=&quot;_blank&quot;&gt;http://mydomain.com?request=2&lt;/a&gt; , etc. 
    $index_id = $info[url][strlen($info[url])-1]; 
    $rc_result[$index_id] = $response ;   
} 
 
$rc = new RollingCurl(&quot;request_callback&quot;); 
$rc-&gt;window_size = 10; 
foreach ($urls as $url) { 
    $request = new Request($url); 
    $rc-&gt;add($request); 
} 
$rc-&gt;execute();     
 
ksort($rc_result,SORT_NUMERIC); 
print_r($rc_result); </description>
		<content:encoded><![CDATA[<p>I need to access Rolling Curl results based on specific URL sequencing. </p>
<p>For smaller requests, I&#039;m using the code below and it&#039;s working fine. </p>
<p>For larger requests, I could write the results to disk with sequential file naming for post sequential compilation, rather than storing all the results in memory. </p>
<p>I&#039;m thinking the best way to handle it dynamically, would be to create a function to write sequentially named files to disk, based on a defined size/memory threshold, otherwise, handle via an in-memory associative array as below. </p>
<p>Thoughts? </p>
<p>function request_callback($response,$info) {<br />
    global $rc_result ;<br />
    // get last character of URL to enable indexing of results<br />
    // e.g., $url[] = <a href="http://mydomain.com?request=1," target="_blank"></a><a href="http://mydomain.com?request=1" rel="nofollow">http://mydomain.com?request=1</a>, $url[] = <a href="http://mydomain.com?request=2" target="_blank">http://mydomain.com?request=2</a> , etc.<br />
    $index_id = $info[url][strlen($info[url])-1];<br />
    $rc_result[$index_id] = $response ;<br />
} </p>
<p>$rc = new RollingCurl(&quot;request_callback&quot;);<br />
$rc-&gt;window_size = 10;<br />
foreach ($urls as $url) {<br />
    $request = new Request($url);<br />
    $rc-&gt;add($request);<br />
}<br />
$rc-&gt;execute();     </p>
<p>ksort($rc_result,SORT_NUMERIC);<br />
print_r($rc_result);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/comment-page-1/#comment-847</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Sun, 31 Jan 2010 18:21:26 +0000</pubDate>
		<guid isPermaLink="false">http://onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/#comment-847</guid>
		<description>Rolling Curl simply just rocks! Thanks for all your time &amp; effort on this. I&#039;m amazed at what this can accomplish on so few CPU cycles. 
 
Who cares whether it&#039;s technically forking, threading, or otherwise....it works as advertised. 
 
One small issue on the blog presentation. While I know it should be obvious that the current code lives on google, I think it would be advantages (from a visual quickscan standpoint) to replace the old code in the black area (on top of the blog post) with the current meat and potatoes, end result, functionality from the example on Google: 
 
&lt;code&gt; 
/* 
authored by Josh Fraser (&lt;a href=&quot;http://www.joshfraser.com)&quot; target=&quot;_blank&quot;&gt;www.joshfraser.com)&lt;/a&gt; 
released under Apache License 2.0 
*/ 
 
// a little example that fetches a bunch of sites in parallel and echos the page title and response info for each request 
 
require(&quot;RollingCurl.php&quot;); 
 
// top 20 sites according to alexa (11/5/09) 
$urls = array(&quot;http://www.google.com&quot;, 
              &quot;http://www.facebook.com&quot;, 
              &quot;http://www.yahoo.com&quot;, 
              &quot;http://www.youtube.com&quot;, 
              &quot;http://www.live.com&quot;, 
              &quot;http://www.wikipedia.com&quot;, 
              &quot;http://www.blogger.com&quot;, 
              &quot;http://www.msn.com&quot;, 
              &quot;http://www.baidu.com&quot;, 
              &quot;http://www.yahoo.co.jp&quot;, 
              &quot;http://www.myspace.com&quot;, 
              &quot;http://www.qq.com&quot;, 
              &quot;http://www.google.co.in&quot;, 
              &quot;http://www.twitter.com&quot;, 
              &quot;http://www.google.de&quot;, 
              &quot;http://www.microsoft.com&quot;, 
              &quot;http://www.google.cn&quot;, 
              &quot;http://www.sina.com.cn&quot;, 
              &quot;http://www.wordpress.com&quot;, 
              &quot;http://www.google.co.uk&quot;); 
 
function request_callback($response, $info) { 
        // parse the page title out of the returned HTML 
        if (eregi (&quot;&lt;title&gt;(.*)&lt;/title&gt;&quot;, $response, $out)) { 
                $title = $out[1]; 
        } 
        echo &quot;&lt;b&gt;$title&lt;/b&gt;&lt;br /&gt;&quot;; 
        print_r($info); 
        echo &quot;&lt;hr&gt;&quot;; 
} 
 
$rc = new RollingCurl(&quot;request_callback&quot;); 
$rc-&gt;window_size = 20; 
foreach ($urls as $url) { 
    $request = new Request($url); 
    $rc-&gt;add($request); 
} 
$rc-&gt;execute(); 
&lt;/code&gt; 
 
And provide the direct Google trunk link for those who are not used to working with a repository: 
 
&lt;a href=&quot;http://code.google.com/p/rolling-curl/source/browse/trunk/&quot; target=&quot;_blank&quot;&gt;http://code.google.com/p/rolling-curl/source/brow...&lt;/a&gt; 
 
I know for myself, when I&#039;m scanning a bunch of sites for the right solution, it&#039;s nice to see a quick visual reference. 
 
Cheers. </description>
		<content:encoded><![CDATA[<p>Rolling Curl simply just rocks! Thanks for all your time &amp; effort on this. I&#039;m amazed at what this can accomplish on so few CPU cycles. </p>
<p>Who cares whether it&#039;s technically forking, threading, or otherwise&#8230;.it works as advertised. </p>
<p>One small issue on the blog presentation. While I know it should be obvious that the current code lives on google, I think it would be advantages (from a visual quickscan standpoint) to replace the old code in the black area (on top of the blog post) with the current meat and potatoes, end result, functionality from the example on Google: </p>
<p>&lt;code&gt;<br />
/*<br />
authored by Josh Fraser (<a href="http://www.joshfraser.com)" target="_blank"></a><a href="http://www.joshfraser.com" rel="nofollow">http://www.joshfraser.com</a>)<br />
released under Apache License 2.0<br />
*/ </p>
<p>// a little example that fetches a bunch of sites in parallel and echos the page title and response info for each request </p>
<p>require(&quot;RollingCurl.php&quot;); </p>
<p>// top 20 sites according to alexa (11/5/09)<br />
$urls = array(&quot;http://www.google.com&quot;,<br />
              &quot;http://www.facebook.com&quot;,<br />
              &quot;http://www.yahoo.com&quot;,<br />
              &quot;http://www.youtube.com&quot;,<br />
              &quot;http://www.live.com&quot;,<br />
              &quot;http://www.wikipedia.com&quot;,<br />
              &quot;http://www.blogger.com&quot;,<br />
              &quot;http://www.msn.com&quot;,<br />
              &quot;http://www.baidu.com&quot;,<br />
              &quot;http://www.yahoo.co.jp&quot;,<br />
              &quot;http://www.myspace.com&quot;,<br />
              &quot;http://www.qq.com&quot;,<br />
              &quot;http://www.google.co.in&quot;,<br />
              &quot;http://www.twitter.com&quot;,<br />
              &quot;http://www.google.de&quot;,<br />
              &quot;http://www.microsoft.com&quot;,<br />
              &quot;http://www.google.cn&quot;,<br />
              &quot;http://www.sina.com.cn&quot;,<br />
              &quot;http://www.wordpress.com&quot;,<br />
              &quot;http://www.google.co.uk&quot;); </p>
<p>function request_callback($response, $info) {<br />
        // parse the page title out of the returned HTML<br />
        if (eregi (&quot;&lt;title&gt;(.*)&lt;/title&gt;&quot;, $response, $out)) {<br />
                $title = $out[1];<br />
        }<br />
        echo &quot;<b>$title</b><br />&quot;;<br />
        print_r($info);<br />
        echo &quot;&lt;hr&gt;&quot;;<br />
} </p>
<p>$rc = new RollingCurl(&quot;request_callback&quot;);<br />
$rc-&gt;window_size = 20;<br />
foreach ($urls as $url) {<br />
    $request = new Request($url);<br />
    $rc-&gt;add($request);<br />
}<br />
$rc-&gt;execute();<br />
&lt;/code&gt; </p>
<p>And provide the direct Google trunk link for those who are not used to working with a repository: </p>
<p><a href="http://code.google.com/p/rolling-curl/source/browse/trunk/" target="_blank"></a><a href="http://code.google.com/p/rolling-curl/source/brow.." rel="nofollow">http://code.google.com/p/rolling-curl/source/brow..</a>. </p>
<p>I know for myself, when I&#039;m scanning a bunch of sites for the right solution, it&#039;s nice to see a quick visual reference. </p>
<p>Cheers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Freaky_gerbil</title>
		<link>http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/comment-page-1/#comment-824</link>
		<dc:creator>Freaky_gerbil</dc:creator>
		<pubDate>Tue, 12 Jan 2010 16:39:35 +0000</pubDate>
		<guid isPermaLink="false">http://onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/#comment-824</guid>
		<description>I get the same problem with the disappearing URL&#039;s as previously mentioned. I have kept the rolling window at 5 and experimented with retrieving XML feeds from Amazon. Once I get up to 50 URLs I am not getting the expected number of results. I have tried adding error handling but there are none, the URL&#039;s just disappear. 
 
About the only thing I can think of at the moment is flagging each URL in the array and recursively processing until they are either flagged as completed or error. I will keep you posted.  </description>
		<content:encoded><![CDATA[<p>I get the same problem with the disappearing URL&#039;s as previously mentioned. I have kept the rolling window at 5 and experimented with retrieving XML feeds from Amazon. Once I get up to 50 URLs I am not getting the expected number of results. I have tried adding error handling but there are none, the URL&#039;s just disappear. </p>
<p>About the only thing I can think of at the moment is flagging each URL in the array and recursively processing until they are either flagged as completed or error. I will keep you posted.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Freaky_gerbil</title>
		<link>http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/comment-page-1/#comment-822</link>
		<dc:creator>Freaky_gerbil</dc:creator>
		<pubDate>Mon, 11 Jan 2010 12:10:04 +0000</pubDate>
		<guid isPermaLink="false">http://onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/#comment-822</guid>
		<description>Perfect just what I was looking for and easy for a NOOB like myself to implement :D Thank you </description>
		<content:encoded><![CDATA[<p>Perfect just what I was looking for and easy for a NOOB like myself to implement <img src='http://www.onlineaspect.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  Thank you</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brad</title>
		<link>http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/comment-page-1/#comment-800</link>
		<dc:creator>Brad</dc:creator>
		<pubDate>Tue, 08 Dec 2009 05:14:30 +0000</pubDate>
		<guid isPermaLink="false">http://onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/#comment-800</guid>
		<description>Thank you for addressing this so quickly! </description>
		<content:encoded><![CDATA[<p>Thank you for addressing this so quickly!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Graham Anderson</title>
		<link>http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/comment-page-1/#comment-799</link>
		<dc:creator>Graham Anderson</dc:creator>
		<pubDate>Mon, 07 Dec 2009 21:42:01 +0000</pubDate>
		<guid isPermaLink="false">http://onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/#comment-799</guid>
		<description>The below works :)  
Does anyone know if there is a way to do it without mucking up the code in the Rolling Curl class?  Many thanks in advance. 
 
I added a reference to the parent class in the Rolling Curl constructer: 
    function __construct($callback = null,$cls=null) { 
        $this-&gt;parentClass = $cls; 
    $this-&gt;callback = $callback; 
 
To target the callback function of the parent class, I replaced: 
                // Send the return values to the callback function. 
                $callback = $this-&gt;callback; 
                $callback($output, $info); 
With: 
$this-&gt;callback=  str_replace(&#039;$this-&gt;&#039;,&#039;&#039;,$this-&gt;callback); //remove &#039;$this-&gt;&#039; from the string 
eval(&#039;$this-&gt;parentClass-&gt;&#039;.$this-&gt;callback.&#039;;&#039;);  
 
In my Parent Class, I called rolling curl like this: 
$callback = &#039;$this-&gt;attributeHTMLScraper($output,$info,&quot;/html/body//a&quot;)&#039;; 
$this-&gt;rc =  new RollingCurl($callback,$this); 
 
 
As an alternative, I tried the below but could not get the $vArgs array to show up in the attributeHTMLScraper function. 
$vArgs = array($response,$info,&#039;/html/body//a&#039;); 
call_user_func_array($this-&gt;parentClass-&gt;attributeHTMLScraper,$vArgs ); 
 
If anyone knows a more elegant way to do this, I would be much appreciative. Still deep in that learning phase. </description>
		<content:encoded><![CDATA[<p>The below works <img src='http://www.onlineaspect.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
Does anyone know if there is a way to do it without mucking up the code in the Rolling Curl class?  Many thanks in advance. </p>
<p>I added a reference to the parent class in the Rolling Curl constructer:<br />
    function __construct($callback = null,$cls=null) {<br />
        $this-&gt;parentClass = $cls;<br />
    $this-&gt;callback = $callback; </p>
<p>To target the callback function of the parent class, I replaced:<br />
                // Send the return values to the callback function.<br />
                $callback = $this-&gt;callback;<br />
                $callback($output, $info);<br />
With:<br />
$this-&gt;callback=  str_replace(&#039;$this-&gt;&#039;,&#039;&#039;,$this-&gt;callback); //remove &#039;$this-&gt;&#039; from the string<br />
eval(&#039;$this-&gt;parentClass-&gt;&#039;.$this-&gt;callback.&#039;;&#039;);  </p>
<p>In my Parent Class, I called rolling curl like this:<br />
$callback = &#039;$this-&gt;attributeHTMLScraper($output,$info,&quot;/html/body//a&quot;)&#039;;<br />
$this-&gt;rc =  new RollingCurl($callback,$this); </p>
<p>As an alternative, I tried the below but could not get the $vArgs array to show up in the attributeHTMLScraper function.<br />
$vArgs = array($response,$info,&#039;/html/body//a&#039;);<br />
call_user_func_array($this-&gt;parentClass-&gt;attributeHTMLScraper,$vArgs ); </p>
<p>If anyone knows a more elegant way to do this, I would be much appreciative. Still deep in that learning phase.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Graham Anderson</title>
		<link>http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/comment-page-1/#comment-798</link>
		<dc:creator>Graham Anderson</dc:creator>
		<pubDate>Mon, 07 Dec 2009 19:26:01 +0000</pubDate>
		<guid isPermaLink="false">http://onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/#comment-798</guid>
		<description>My question above my be more of an OOP usage question than a rolling-curl question.  That said, any help is greatly appreciated.  </description>
		<content:encoded><![CDATA[<p>My question above my be more of an OOP usage question than a rolling-curl question.  That said, any help is greatly appreciated.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Graham Anderson</title>
		<link>http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/comment-page-1/#comment-797</link>
		<dc:creator>Graham Anderson</dc:creator>
		<pubDate>Sat, 05 Dec 2009 20:54:05 +0000</pubDate>
		<guid isPermaLink="false">http://onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/#comment-797</guid>
		<description>Ok, after a little testing, the below works: 
Works: 
$callback = $this-&gt;sayHello(&quot;Is this parent method being called?&quot;); 
$this-&gt;rc =  new RollingCurl($callback); 
 
Doesn&#039;t Work: ($response, $info is null, $scrape works): 
$callback =  $this-&gt;attributeHTMLScraper($response,$info,$scrape=&quot;/html/body//a&quot;); 
$this-&gt;rc =  new RollingCurl($callback); 
 
Here is the attributeHTMLScraper method in the parent class: 
public function attributeHTMLScraper($response,$info,$scrape) 
{ 
var_dump($response); var_dump($info); //Both Null 
$dom = new DOMDocument(); 
$dom-&gt;loadHTML($reponse); 
 
$xpath = new DOMXPath($dom); 
$hrefs = $xpath-&gt;evaluate($scrape); 
 
if(!is_null($hrefs)): 
for ($i = 0; $i &lt; $hrefs-&gt;length; $i++): 
$href = $hrefs-&gt;item($i); 
$url = $href-&gt;getAttribute(&#039;href&#039;); 
$result[] =$url; 
endfor; 
endif; 
 
//Return a simple variable if 1 value is returned. Else return an array 
if(count($result)==1): 
return $result[0]; 
else: 
return $result; 
endif; 
 
 
return $result; 
} 
 
 
How can I pass these parent methods to the callback variable?   
 
 </description>
		<content:encoded><![CDATA[<p>Ok, after a little testing, the below works:<br />
Works:<br />
$callback = $this-&gt;sayHello(&quot;Is this parent method being called?&quot;);<br />
$this-&gt;rc =  new RollingCurl($callback); </p>
<p>Doesn&#039;t Work: ($response, $info is null, $scrape works):<br />
$callback =  $this-&gt;attributeHTMLScraper($response,$info,$scrape=&quot;/html/body//a&quot;);<br />
$this-&gt;rc =  new RollingCurl($callback); </p>
<p>Here is the attributeHTMLScraper method in the parent class:<br />
public function attributeHTMLScraper($response,$info,$scrape)<br />
{<br />
var_dump($response); var_dump($info); //Both Null<br />
$dom = new DOMDocument();<br />
$dom-&gt;loadHTML($reponse); </p>
<p>$xpath = new DOMXPath($dom);<br />
$hrefs = $xpath-&gt;evaluate($scrape); </p>
<p>if(!is_null($hrefs)):<br />
for ($i = 0; $i &lt; $hrefs-&gt;length; $i++):<br />
$href = $hrefs-&gt;item($i);<br />
$url = $href-&gt;getAttribute(&#039;href&#039;);<br />
$result[] =$url;<br />
endfor;<br />
endif; </p>
<p>//Return a simple variable if 1 value is returned. Else return an array<br />
if(count($result)==1):<br />
return $result[0];<br />
else:<br />
return $result;<br />
endif; </p>
<p>return $result;<br />
} </p>
<p>How can I pass these parent methods to the callback variable?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
