简体   繁体   English

需要通过WSDL返回对大量数据进行排序

[英]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. 我们拥有WSDL Web服务,该服务返回全球各国认证工厂的名称和联系信息。 It accepts a three letter string as the parameter (ie BGD for Bangladesh, CHN for China, COL for Colombia). 它接受三个字母的字符串作为参数(例如,孟加拉国为BGDCHNCHN ,哥伦比亚为COL )。

I've designed a page with an HTML select so that the user can pick a country and see a list of factories. 我设计了一个带有HTML选择的页面,以便用户可以选择一个国家并查看工厂列表。 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. (为简洁起见,我只包括了前几个国家。完整的数组包括大约210个国家。而且, factCountByCountryID()函数返回给定国家/地区中当前的工厂数量。

<?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? 如果我们假设您可以修改Web服务,那么我认为解决方案很明显?

You would make a new function called "getCountriesWithFactories()". 您将创建一个名为“ 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). 您可以将此服务添加到Web服务并在数据库中运行查询,而不是尝试将其过滤出客户端(在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. 编写一个MySQL查询(或您正在使用的任何东西)应该很容易做到这一点。

The reason it's slow now is that you are looping over every country and making one HTTP call per country. 现在它变慢的原因是,您正在遍历每个国家/地区,并在每个国家/地区进行一次HTTP调用。 So for every page load you make 210 calls to the web service. 因此,对于每个页面加载,您都会对Web服务进行210次调用。

If you can implement the getCountriesWithFactories method instead, you'll only make 1 call per page load. 如果可以改为实现getCountriesWithFactories方法,则每个页面加载仅调用1次。

Hope that makes sense. 希望有道理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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