Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3981692
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:26:26+00:00 2026-05-20T05:26:26+00:00

I’m having trouble creating multiple xml requests using php’s curl_multi_exec. The problem is that

  • 0

I’m having trouble creating multiple xml requests using php’s curl_multi_exec.

The problem is that the do…while loop containing the curl_multi_exec command runs only once and then quits.

Resources Used:

http://www.phpied.com/simultaneuos-http-requests-in-php-with-curl/
http://php.net/manual/en/function.curl-multi-exec.php/
http://www.rustyrazorblade.com/2008/02/curl_multi_exec/

Take a look at my code:

    //Multi handle curl initialization
    $mh = curl_multi_init();

    //set url
    $url = 'my_url';

    foreach($latLng as $id => $l) {
        $ch[$id] = curl_init();

        //$request previously set                

        //Initialize and set options 
        curl_setopt($ch, CURLOPT_URL,                $url);
        curl_setopt($ch, CURLOPT_HEADER,             0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,     1);
        curl_setopt($ch, CURLOPT_POST,               1);
        curl_setopt($ch, CURLOPT_POSTFIELDS,        $request); 

        //add to multi_handle
        curl_multi_add_handle($mh, $ch[$id]);
    }

    //Execute the handles
    $running = null;

    do {
        $mrc = curl_multi_exec($mh, $running);   
        $ready=curl_multi_select($mh);
        echo "Ran once\n";
    } while ($mrc == CURLM_CALL_MULTI_PERFORM && $ready > 0);

    while ($active && $mrc == CURLM_OK) {
        if ($curl_multi_select($mh) != -1) {
            do {
                $mrc = curl_multi_exec($mh, $running);
                echo "Ran again\n";
            } while ($mrc == CURLM_CALL_MULTI_PERFORM);
        }
    }

    foreach ($mh as $c) {
        // HTTP response code
        $code = curl_getinfo($c,  CURLINFO_HTTP_CODE);

        // cURL error number
        $curl_errno = curl_errno($c);

        // cURL error message   
        $curl_error = curl_error($c);

        // output if there was an error                                                            
        if ($curl_error) {
            echo("*** cURL error: ($curl_errno) $curl_error\n");
        }
    }

    //get content and remove handles
    foreach ($ch as $c) {
        $result[] = curl_multi_getcontent($c);  
        curl_multi_remove_handle($mh, $c);  
    }   

    print_r($result);

    //Close curl
    curl_multi_close($mh);
}

I know the request is valid because I receive the correct return data when I perform a single curl execution. The problem lies with the curl_multi_exec().

The output I am receiving is “Ran once” followed by the empty arrays of the curl_multi_getcontent() calls. See below:

Ran once
Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
)

Any help is greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:26:27+00:00Added an answer on May 20, 2026 at 5:26 am

    You’re not setting up the curl options correctly:

    Currently, you’re setting options on $ch which is your array, you need to be setting the options specifically on the current curl handler, which in your loop is $ch[$id]:

       //Initialize and set options 
       curl_setopt($ch[$id], CURLOPT_URL,                $url);
       curl_setopt($ch[$id], CURLOPT_HEADER,             0);
       curl_setopt($ch[$id], CURLOPT_RETURNTRANSFER,     1);
       curl_setopt($ch[$id], CURLOPT_POST,               1);
       curl_setopt($ch[$id], CURLOPT_POSTFIELDS,        $request); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.