tags:

views:

36

answers:

2

I am having problems with cURL not being able to connect to a server that returns an xml feed and am not sure if my code is stacking up and causing the problem. Is it possible the final function called in this foreach loop is still running when the next loop iteration comes round.

Is it possible to make sure all functions in the loop complete before the next iteration begins, or does foreach do this by default anyway? I tried setting a return true on process_xml() and running a test in the loop: if($this->process_xml($xml_array))continue; but it didn't seem to have an effect and seems like a bad idea anyway.

foreach($arrayOfUrls as $url){

    //retrieve xml from url as string.
    if($url_xml_string = $this->getFeedStringUsing_cURL($url)){
        $xml_object = simplexml_load_string($url_xml_string);
        $xml_array = $this->feedStringToArray($xml_object);
        //process the xml.
        $this->process_xml($xml_array);
    }                                 
}
+1  A: 

No, this is not possible. Each statement is executed and finished before the next statement is run.

Sjoerd
A: 

and am not sure if my code is stacking up

Not sure? If it's important to you why don't you find out? Without knowing what OS you are running on its rather hard to advise how you'd go about that - but netstat might be a good starting point.

Is it possible the final function called in this foreach loop is still running

It's highly improbable - PHP scripts run in a single thread of execution unless you tell them not to - but the curl extension allows you to define callbacks into your php code which run before the operation completes, and the curl_multi_ family of functions also allow you to run php code while requests are in progress.

symcbean