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


curl-multi: removing handles problem

From: stuff <>
Date: Fri, 14 Mar 2008 22:09:25 -0400

First the basics: Running PHP version 5.2.5, with Curl information:
libcurl/7.15.5 OpenSSL/0.9.8c zlib/1.2.3 libidn/0.6.5
I run a script that processes large queues of URLs, and uses curl_multi with
10 handles to collect ten at a time. This has always worked just fine, but
has recently run into problems, following a server upgrade, probably with
new PHP installation. The code is fairly basic (I copied an example from
somewhere), but I'm adding the relevant bits here in case there's an obvious
problem. It hasn't changed at all from what it's been for several year now:
      for ($i=0;$i<$chc;$i++) {
      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);
///////// content is processed here
      for ($i=0;$i<$chc;$i++) {

The culti-multi handle is initialized once, and is reused to go through the
next set of 10 URLs. Similarly, each of the 10 curl handles is initialized
once, and reused.
It's this last bit where the problem arises: my script aborts during the
last (10th) curl_multi_remove_handle call. This could be because some error
(none are reported, though), or because that last call triggers a CPU
timeout or memory usage abort from my web server. Does something happen when
the last of the handles is removed from the curl-multi handle? Am I going
about this problem the wrong way? Is there an easier way to assign a new set
of URLs to be processed without removing and re-adding the individual
I would very much appreciate any words of help

Received on 2008-03-15