cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

RE: Starting to learn curl-multi

From: Broekhuis,Robert R. <BROEKHRR_at_airproducts.com>
Date: Thu, 5 Jan 2006 09:31:39 -0500

Thanks for the help.

>> When using single-thread functions in the past, I happily reused the
>> same handle over and over, with a single init() up front and a single

>> close() at the end. This does not appear to work for multi-thread
>> handles - must I
>> init()/close() them for every use

>Then something is wrong. Either in your app, in PHP/CURL or in
libcurl...

I found my answer, I think, on the page you referred me to:

[quote from libcurl multi page]
If you want to re-use an easy handle that was added to the multi handle
for transfer, you must first remove it from the multi stack and then
re-add it again (possibly after having altered some options at your own
choice).
[end quote]

I hadn't done that.

>I figure that is the PHP/CURL version of curl_multi_fdset()
>and thus it extracts info from libcurl to allow your app to
>select() for actions on the sockets libcurl handles.

That's a language context I'm not familiar with - where can I read about
how select() works? How does it pertain to the php context? And most
pertinently - how would I use these functions in such a way as to
process completed connections as they become available? I understand the
bit about the number of active connections ($active in the code below)
decreasing, but how do I then go and figure out which connection handle
is the one to process? And finally - is it OK to start a new curl_easy
request on one of the complete handles (or an independent one) while
curl_multi is still processing?

My current code (Mostly from the php site example) is copied below:

      $mh = curl_multi_init();
      for ($i=0;$i<$chc;$i++) {
         $chh[$i]=curl_init();
         curl_multi_add_handle ($mh,$chh[$i]);
         curl_setopt($chh[$i],CURLOPT_URL,$chu[$i]);
         curl_setopt($chh[$i],CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($chh[$i],CURLOPT_FOLLOWLOCATION,1);
         curl_setopt($chh[$i],CURLOPT_TIMEOUT,30);
      }
      do {
         $mrc = curl_multi_exec($mh, $active);
      } while ($mrc == CURLM_CALL_MULTI_PERFORM);
      while ($active and $mrc == CURLM_OK) {
         if (curl_multi_select($mh) != -1) {
            do {
               $mrc = curl_multi_exec($mh, $active);
            } while ($mrc == CURLM_CALL_MULTI_PERFORM);
         }
      }
      if ($mrc != CURLM_OK) {
         print "Curl multi read error $mrc\n";
      }
      for ($i=0;$i<$chc;$i++) {
         $page=curl_multi_getcontent($chh[$i]);
         do_url($chh[$i],$chu[$i]);
      }

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2006-01-05