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 3488530
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:16:56+00:00 2026-05-18T11:16:56+00:00

So the gist is that I need to post XML data query to a

  • 0

So the gist is that I need to post XML data query to a gateway page to receive a XML response which O parse later, there can be anywhere from 3-60 queries to this web service, I unfortunately have to run a simple loop right now and do them one at a time. On the response side, I will only need 1 (or a max of 5) of the lines in the response, line 2 is the first line that I need containing image data. So I’d like the ability to select which lines I am reading in if at all possible.

I created a simple “Read in” function as I said out of a basic for loop, here’s the code that I am currently using and would like to revise.


$part1 = 'XML Beginning'; $part2 = XML End';
$posts = array( 0 => 'SC-010052214', 1 => 'SC-000032972', 2 => 'SC-012535460', 3 => 'SC-011257289', 4 => 'SC-010134078' );


 $ch = curl_init();

  curl_setopt($ch, CURLOPT_URL, 'http://example.com/index.php');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER => 1);
  curl_setopt ($ch, CURLOPT_POST, 1);

 $count = count($posts);
 for($i=0;$i<$count;$i++) {

  curl_setopt ($ch, CURLOPT_POSTFIELDS, "payload=$part1{$posts[$i]}$part2");
  $return[] = curl_exec ($ch);

  }
 curl_close ($ch); 

print_r($return);

Restrictions: I cannot use ?post=$data0&post=$data1&post=$data3 unfortunately, so I need a better solution. Other than that, I’d like to see what kinds of improvements can be made here.

  • 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-18T11:16:56+00:00Added an answer on May 18, 2026 at 11:16 am

    Because of limits in quick response,

    <?php
    
    function m_curl($input) {
    
            // compile queries for usable locations
            foreach($input['content'] as $pos=>$item) {
                $query = '<childDetailQuery><request><query-replacement>';
                $query .= "<item_number>{$item}</item_number>";
    
                        $query .= (isset($input['story']) && $input['story'] != NULL) 
                                    ? "<story_type>".$input['story']."</story_type>"
                                    : '<story_type>SHORT</story_type>';
    
                        $query .= (isset($input['party']) && $input['party'] != NULL) 
                                    ? "<party_number>".$input['party']."</party_number>"
                                    : '';
    
                $query .= "</query-replacement><latency-tolerance>NONE</latency-tolerance>";
                $query .= '</request></childDetailQuery>';
    
            $queries[] = $query;
                    unset($query);
            }
    
    
            // make sure the rolling window isn't greater than the # of urls
            $limit = 10;
            $limit = (sizeof($queries) < $limit) ? sizeof($queries) : $limit;
    
            $master = curl_multi_init();
            $curl_arr = array();
    
                // add additional curl options here
                $std_options = array(
                    CURLOPT_RETURNTRANSFER => 1,
                    CURLOPT_FOLLOWLOCATION => 1,
                    CURLOPT_MAXREDIRS => 0,
                );
    
            $options = ($coptions) ? ($std_options + $coptions) : $std_options;
    
            echo $input['location'];
            // start the first batch of requests
            for ($i = 0; $i < $limit; $i++) {
                $ch = curl_init();
    
                    $options[CURLOPT_POSTFIELDS] = "payload=".$queries[$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) {
                                        echo 'Curl Error'; break;
                    }
    
    
                // a request was just completed -- find out which one
                while($done = curl_multi_info_read($master)) {
                    $info = curl_getinfo($done['handle']);
                    if ($info['http_code'] == 200)  {
                        $output = curl_multi_getcontent($done['handle']);
    
                        // request successful.  process output using the callback function.
                        parse_returns($output);
    
                        // start a new request (it's important to do this before removing the old one)
                        $ch = curl_init();
                        $options[CURLOPT_POSTFIELDS] = "payload=".$queries[$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['handle']);
    
                    } else {
    
                        echo 'Failed on:'; var_dump($info);
                        echo 'With options:'; var_dump($options);
    
                        // request failed.  add error handling.
                    }
                }
            } while ($running);
    
            curl_multi_close($master);
            return false;
    }
    
    function parse_returns($data) {
        print_r($data);
    }
    
    // set query numbers
    $data = array(
        0 => 'SC-010052214',
        1 => 'SC-000032972',
        2 => 'SC-012535460',
        3 => 'SC-011257289',
        4 => 'SC-010134078'
    );
    
    // set options array
    $options = array(
        'location'      => 'http://ibudev.wvus.org/websvc/actions/wvsMessageRouter.php',
        'readline'      => 2,
        'coptions'      => NULL,
        'content'       => $data,
        'story'         => 'FULL',
        'party'         => NULL,
    );
    
    
    m_curl($options);
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.