简体   繁体   中英

Need to sort large amount of data via a WSDL return

I have a complex problem that I need some guidance on. We are a non-profit that certifies factories throughout the world as ethical or not. We have a WSDL web service that returns the names and contact info for certified factories in countries around the globe. It accepts a three letter string as the parameter (ie BGD for Bangladesh, CHN for China, COL for Colombia).

I've designed a page with an HTML select so that the user can pick a country and see a list of factories. I'd like to be able to write a filter of some kind that only puts countries with certified factories in this list and keeps out the ones that don't.

I have written the following code that does get this done, however it is excruciatingly slow and really bogs down the site. (For the sake of brevity, I have included only the first few countries. The full array includes about 210 countries. Also, the factCountByCountryID() function returns the number of factories currently in the given country.

<?php
ini_set("soap.wsdl_cache_enabled", "0");    
$client = new SoapClient("http://apollov-dev.worlddata.com:8080/WrapSystem/services/FactoriesWS?wsdl",array("trace" => 1,     "exceptions" => 0));

$countryList=array("AFG"=>"Afghanistan","ALA"=>"Aland Islands","ALB"=>"Albania","DZA"=>"Algeria","ASM"=>"American Samoa","AND"=>"Andorra","AGO"=>"Angola","AIA"=>"Anguilla","ATG"=>"Antigua and Barbuda","ARG"=>"Argentina","ARM"=>"Armenia","ABW"=>"Aruba","AUS"=>"Australia","AUT"=>"Austria","AZE"=>"Azerbaijan","BHS"=>"Bahamas","BHR"=>"Bahrain","BGD"=>"Bangladesh","BRB"=>"Barbados","BLR"=>"Belarus","BEL"=>"Belgium","BLZ"=>"Belize","BEN"=>"Benin","BMU"=>"Bermuda","BTN"=>"Bhutan","BOL"=>"Bolivia","BIH"=>"Bosnia and Herzegovina","BWA"=>"Botswana","BRA"=>"Brazil","VGB"=>"British Virgin Islands","BRN"=>"Brunei Darussalam","BGR"=>"Bulgaria","BFA"=>"Burkina Faso","BDI"=>"Burundi","KHM"=>"Cambodia","CMR"=>"Cameroon","CAN"=>"Canada","CPV"=>"Cape Verde","CYM"=>"Cayman Islands");


foreach($countryList as $code=>$country)
{
    $params->countryCd=$code;
    $number=$client->factCountByCountryID($params);
    $factval=$number->factCountByCountryIDReturn;
    if($factval!=0)
    {
        $countriesWithFactories["$code"]="$country";
    }
    else continue;
}



?>

If we assume you can modify the web service, then I think the solution is pretty obvious?

You would make a new function called "getCountriesWithFactories()". You can add this service to the web service and run the query in the database instead of trying to filter it out client side (in PHP).

The call just returns any countries that have a factory. It should be very easy to write a MySQL query (or whatever you're using) to do that.

The reason it's slow now is that you are looping over every country and making one HTTP call per country. So for every page load you make 210 calls to the web service.

If you can implement the getCountriesWithFactories method instead, you'll only make 1 call per page load.

Hope that makes sense.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM